Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

/**
* Implementation utilities (details) affecting the way JSON objects are wrapped.
*
* <p>
* This class is copied from {@code io.vertx.core.json.impl.JsonUtil} as it is internal to Vert.x
*/
public final class JsonUtil {
Expand Down Expand Up @@ -50,16 +50,17 @@ public final class JsonUtil {
* @param val java type
* @return wrapped type or {@code val} if not applicable.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Object wrapJsonValue(Object val) {
if (val == null) {
return null;
}

// perform wrapping
if (val instanceof Map) {
val = new JsonObject((Map) val);
} else if (val instanceof List) {
val = new JsonArray((List) val);
if (val instanceof Map map) {
val = new JsonObject(map);
} else if (val instanceof List list) {
val = new JsonArray(list);
} else if (val instanceof Instant) {
val = ISO_INSTANT.format((Instant) val);
} else if (val instanceof byte[]) {
Expand All @@ -73,7 +74,7 @@ public static Object wrapJsonValue(Object val) {
return val;
}

@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "StatementWithEmptyBody", "rawtypes" })
public static Object checkAndCopy(Object val) {
if (val == null) {
// OK
Expand All @@ -92,12 +93,10 @@ public static Object checkAndCopy(Object val) {
// Shareable objects know how to copy themselves, this covers:
// JsonObject, JsonArray or any user defined Shareable type
val = ((Shareable) val).copy();
} else if (val instanceof Map) {
val = (new JsonObject((Map) val)).copy();
} else if (val instanceof List) {
val = (new JsonArray((List) val)).copy();
} else if (val instanceof Buffer) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed because instanceof Shareable already makes the check

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! Yes, we were a bit fast when we migrated that code to Vert.x 5.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would never have seen if it were not for IntelliJ flagging it :)

val = ((Buffer) val).copy();
} else if (val instanceof Map map) {
val = (new JsonObject(map)).copy();
} else if (val instanceof List list) {
val = (new JsonArray(list)).copy();
} else if (val instanceof byte[]) {
// OK
} else if (val instanceof Instant) {
Expand Down
Loading