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 asJsonNode
in 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> V
readAtomicValue(com.fasterxml.jackson.databind.JsonNode node, Class<V> type)
static <V> V
readValue(com.fasterxml.jackson.databind.JsonNode node, Class<V> type)
static <V> V
readValue(com.fasterxml.jackson.databind.JsonNode node, Class<V> type, boolean required)
static <V> V
readValue(com.fasterxml.jackson.databind.JsonNode node, String fieldName, Class<V> type, boolean required)
private static void
writeNumber(com.fasterxml.jackson.core.JsonGenerator jgen, Number value)
static void
writeValue(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
- theJsonNode
to parse.fieldName
- the name of theJSON property to read
from theJsonNode
.type
- theClass
reflecting the type of the requested value.required
- -true
if the value is required and an exception shall be thrown if missing,false
otherwise (make it optional and returnnull
if not present).- Returns:
- the parsed value. May be
null
ifrequired
isfalse
. - 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
- theJsonNode
to parse.type
- theClass
reflecting the type of the requested value.required
- -true
if the value is required and an exception shall be thrown if missing,false
otherwise (make it optional and returnnull
if not present).- Returns:
- the parsed value. May be
null
ifrequired
isfalse
. - 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
- theJsonNode
to parse.type
- theClass
reflecting the type of the requested value.- Returns:
- the parsed value. May be
null
ifrequired
isfalse
. - Throws:
RuntimeException
- in case of an error.
-
readAtomicValue
private static <V> V readAtomicValue(com.fasterxml.jackson.databind.JsonNode node, Class<V> type)
-
-