diff --git a/flow-server/src/main/java/com/vaadin/flow/internal/JacksonCodec.java b/flow-server/src/main/java/com/vaadin/flow/internal/JacksonCodec.java
index 374ed784a05..218d1b9441c 100644
--- a/flow-server/src/main/java/com/vaadin/flow/internal/JacksonCodec.java
+++ b/flow-server/src/main/java/com/vaadin/flow/internal/JacksonCodec.java
@@ -47,7 +47,7 @@
* For internal use only. May be renamed or removed in a future release.
*
* @author Vaadin Ltd
- * @since 1.0
+ * @since 24.7
*/
public class JacksonCodec {
/**
@@ -217,7 +217,8 @@ public static JsonNode encodeWithoutTypeInfo(Object value) {
/**
* Helper for decoding any "primitive" value that is directly supported in
* JSON. Supported values types are {@link String}, {@link Number},
- * {@link Boolean}, {@link JsonNode}. null
is also supported.
+ * {@link Boolean}, {@link JsonNode}.
+ * {@link com.fasterxml.jackson.databind.node.NullNode} is also supported.
*
* @param json
* the JSON value to decode
diff --git a/flow-server/src/main/java/com/vaadin/flow/internal/JacksonUtils.java b/flow-server/src/main/java/com/vaadin/flow/internal/JacksonUtils.java
index 5e8d53c769d..3b742ac5460 100644
--- a/flow-server/src/main/java/com/vaadin/flow/internal/JacksonUtils.java
+++ b/flow-server/src/main/java/com/vaadin/flow/internal/JacksonUtils.java
@@ -49,7 +49,7 @@
* For internal use only. May be renamed or removed in a future release.
*
* @author Vaadin Ltd
- * @since 1.0
+ * @since 24.7
*/
public final class JacksonUtils {
@@ -89,7 +89,7 @@ public static ArrayNode createArrayNode() {
* Collects a stream of JSON values to a JSON array.
*
* @author Vaadin Ltd
- * @since 1.0
+ * @since 24.7
*/
private static final class ArrayNodeCollector
implements Collector {
@@ -172,18 +172,45 @@ public static boolean jsonEquals(JsonNode a, JsonNode b) {
};
}
+ /**
+ * Compare String value of two JsonNode values.
+ *
+ * @param a
+ * Value one
+ * @param b
+ * Value two
+ * @return {@code true} if text content equals
+ */
public static boolean stringEqual(JsonNode a, JsonNode b) {
assert a.getNodeType() == JsonNodeType.STRING;
assert b.getNodeType() == JsonNodeType.STRING;
return a.asText().equals(b.asText());
}
+ /**
+ * Compare boolean value of two JsonNode values.
+ *
+ * @param a
+ * Value one
+ * @param b
+ * Value two
+ * @return {@code true} if text boolean equals
+ */
public static boolean booleanEqual(JsonNode a, JsonNode b) {
assert a.getNodeType() == JsonNodeType.BOOLEAN;
assert b.getNodeType() == JsonNodeType.BOOLEAN;
return a.asBoolean() == b.asBoolean();
}
+ /**
+ * Compare number value of two JsonNode values.
+ *
+ * @param a
+ * Value one
+ * @param b
+ * Value two
+ * @return {@code true} if number content equals
+ */
public static boolean numbersEqual(JsonNode a, JsonNode b) {
assert a.getNodeType() == JsonNodeType.NUMBER;
assert b.getNodeType() == JsonNodeType.NUMBER;
@@ -216,13 +243,9 @@ private static boolean jsonObjectEquals(JsonNode a, JsonNode b) {
return true;
}
- public static List getKeys(JsonNode a) {
+ public static List getKeys(JsonNode node) {
List keys = new ArrayList<>();
- for (Iterator> it = a.fields(); it
- .hasNext();) {
- Map.Entry entry = it.next();
- keys.add(entry.getKey());
- }
+ node.fieldNames().forEachRemaining(keys::add);
return keys;
}
@@ -391,7 +414,7 @@ public static ObjectNode mapToJson(Map map) {
public static T readToObject(ObjectNode jsonObject, Class tClass) {
Objects.requireNonNull(jsonObject, CANNOT_CONVERT_NULL_TO_OBJECT);
try {
- return objectMapper.readValue(jsonObject.toString(), tClass);
+ return objectMapper.treeToValue(jsonObject, tClass);
} catch (JsonProcessingException e) {
throw new JsonDecodingException(
"Error converting JsonObject to " + tClass.getName(), e);
@@ -410,13 +433,7 @@ public static T readToObject(ObjectNode jsonObject, Class tClass) {
* type of result instance
*/
public static T readValue(ObjectNode jsonValue, Class tClass) {
- Objects.requireNonNull(jsonValue, CANNOT_CONVERT_NULL_TO_OBJECT);
- try {
- return objectMapper.readValue(jsonValue.toString(), tClass);
- } catch (JsonProcessingException e) {
- throw new JsonDecodingException(
- "Error converting ObjectNode to " + tClass.getName(), e);
- }
+ return readToObject(jsonValue, tClass);
}
/**
@@ -434,7 +451,7 @@ public static T readValue(ObjectNode jsonValue,
TypeReference typeReference) {
Objects.requireNonNull(jsonValue, CANNOT_CONVERT_NULL_TO_OBJECT);
try {
- return objectMapper.readValue(jsonValue.toString(), typeReference);
+ return objectMapper.treeToValue(jsonValue, typeReference);
} catch (JsonProcessingException e) {
throw new JsonDecodingException("Error converting ObjectNode to "
+ typeReference.getType().getTypeName(), e);