Class JacksonUtil
- java.lang.Object
-
- com.devonfw.module.json.common.base.JacksonUtil
-
public class JacksonUtil extends Object
Utility class providing static method to help serializing and de-serializing complex object hierarchies with Jackson. To get the current sub-tree of the JSON asJsonNodein aJsonDeserializer, you can simply use the following code:jp.getCodec().readTree(jp)- Since:
- 3.0.0
-
-
Constructor Summary
Constructors Constructor Description JacksonUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static <V> VreadAtomicValue(com.fasterxml.jackson.databind.JsonNode node, Class<V> type)static <V> VreadValue(com.fasterxml.jackson.databind.JsonNode node, Class<V> type)static <V> VreadValue(com.fasterxml.jackson.databind.JsonNode node, Class<V> type, boolean required)static <V> VreadValue(com.fasterxml.jackson.databind.JsonNode node, String fieldName, Class<V> type, boolean required)private static voidwriteNumber(com.fasterxml.jackson.core.JsonGenerator jgen, Number value)static voidwriteValue(com.fasterxml.jackson.core.JsonGenerator jgen, Object value)
-
-
-
Method Detail
-
writeValue
public static void writeValue(com.fasterxml.jackson.core.JsonGenerator jgen, Object value) throws IOException- Parameters:
jgen- theJsonGenerator.value- the value to write depending on its type.- Throws:
IOException- in case of an I/O error.
-
writeNumber
private static void writeNumber(com.fasterxml.jackson.core.JsonGenerator jgen, Number value) throws IOException- Throws:
IOException
-
readValue
public static <V> V readValue(com.fasterxml.jackson.databind.JsonNode node, String fieldName, Class<V> type, boolean required)- Type Parameters:
V- the generic type of the value to read.- Parameters:
node- theJsonNodeto parse.fieldName- the name of theJSON property to readfrom theJsonNode.type- theClassreflecting the type of the requested value.required- -trueif the value is required and an exception shall be thrown if missing,falseotherwise (make it optional and returnnullif not present).- Returns:
- the parsed value. May be
nullifrequiredisfalse. - Throws:
RuntimeException- in case of an error.
-
readValue
public static <V> V readValue(com.fasterxml.jackson.databind.JsonNode node, Class<V> type, boolean required)- Type Parameters:
V- the generic type of the value to read.- Parameters:
node- theJsonNodeto parse.type- theClassreflecting the type of the requested value.required- -trueif the value is required and an exception shall be thrown if missing,falseotherwise (make it optional and returnnullif not present).- Returns:
- the parsed value. May be
nullifrequiredisfalse. - Throws:
RuntimeException- in case of an error.
-
readValue
public static <V> V readValue(com.fasterxml.jackson.databind.JsonNode node, Class<V> type)- Type Parameters:
V- the generic type of the value to read.- Parameters:
node- theJsonNodeto parse.type- theClassreflecting the type of the requested value.- Returns:
- the parsed value. May be
nullifrequiredisfalse. - Throws:
RuntimeException- in case of an error.
-
readAtomicValue
private static <V> V readAtomicValue(com.fasterxml.jackson.databind.JsonNode node, Class<V> type)
-
-