Improve JacksonUtil

This commit is contained in:
Igor Kulikov 2022-01-14 16:55:13 +02:00
parent dd053a8886
commit ff17387767

View File

@ -107,6 +107,14 @@ public class JacksonUtil {
}
}
public static <T> T treeToValue(JsonNode node, Class<T> clazz) {
try {
return OBJECT_MAPPER.treeToValue(node, clazz);
} catch (IOException e) {
throw new IllegalArgumentException("Can't convert value: " + node.toString(), e);
}
}
public static ObjectNode newObjectNode() {
return OBJECT_MAPPER.createObjectNode();
}
@ -121,10 +129,6 @@ public class JacksonUtil {
return OBJECT_MAPPER.valueToTree(value);
}
public static <T> T treeToValue(JsonNode tree, Class<T> type) throws JsonProcessingException {
return OBJECT_MAPPER.treeToValue(tree, type);
}
public static <T> byte[] writeValueAsBytes(T value) {
try {
return OBJECT_MAPPER.writeValueAsBytes(value);