public class JsonHelperJackson2 extends java.lang.Object implements JsonHelper
Modifier and Type | Class and Description |
---|---|
static class |
JsonHelperJackson2.BigIntegerSerializer |
Constructor and Description |
---|
JsonHelperJackson2() |
JsonHelperJackson2(com.fasterxml.jackson.databind.ObjectMapper objectMapper) |
Modifier and Type | Method and Description |
---|---|
static com.fasterxml.jackson.databind.ObjectMapper |
configureMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) |
boolean |
contains(java.lang.Object object,
java.lang.String... path)
This method retrieves if there is a field/value for the given path.
|
<T> T |
convert(java.lang.Object object,
java.lang.Class<T> instanceClass,
java.lang.String... path)
It converts a object (for example a native json object or a map) into another type (like a
statically type DTO).
|
java.math.BigInteger |
getBigInteger(java.lang.Object object,
java.lang.String... path)
This method retrieves a BigInteger attribute following the the provided path
|
java.lang.Boolean |
getBoolean(java.lang.Object object,
java.lang.String... path)
This method retrieves a Long attribute following the the provided path
|
java.lang.Integer |
getInteger(java.lang.Object object,
java.lang.String... path)
This method retrieves a Integer attribute following the the provided path
|
java.lang.Long |
getLong(java.lang.Object object,
java.lang.String... path)
This method retrieves a Long attribute following the the provided path
|
java.lang.Object |
getObject(java.lang.Object object,
java.lang.String... path)
A generic object form the given payload.
|
java.lang.String |
getString(java.lang.Object object,
java.lang.String... path)
This method retrieves a Long attribute following the the provided path
|
java.lang.Object |
parse(java.lang.String string)
It parse a json string into an object of the underlying implementation (e.g.
|
<T> T |
parse(java.lang.String string,
java.lang.Class<T> clazz)
It parse a json string into a an object of the given class.
|
<T> java.util.List<T> |
parseList(java.lang.String string,
java.lang.Class<T> clazz)
It parse a json string into an object list of the given class.
|
java.lang.String |
prettyPrint(java.lang.Object object)
It serializes an object into pretty json string.
|
java.lang.String |
print(java.lang.Object object)
It serializes an object into json.
|
public JsonHelperJackson2(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
public JsonHelperJackson2()
public static com.fasterxml.jackson.databind.ObjectMapper configureMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
public java.lang.Object parse(java.lang.String string)
JsonHelper
parse
in interface JsonHelper
string
- the json stringpublic <T> java.util.List<T> parseList(java.lang.String string, java.lang.Class<T> clazz)
JsonHelper
parseList
in interface JsonHelper
T
- the type of the parsed objectstring
- the json stringclazz
- the class of the parsed objectpublic <T> T parse(java.lang.String string, java.lang.Class<T> clazz)
JsonHelper
parse
in interface JsonHelper
T
- the type of the parsed objectstring
- the json stringclazz
- the class of the parsed objectpublic java.lang.String print(java.lang.Object object)
JsonHelper
print
in interface JsonHelper
object
- the object (json native object, MAP or DTO)public java.lang.String prettyPrint(java.lang.Object object)
JsonHelper
prettyPrint
in interface JsonHelper
object
- the object (json native object, MAP or DTO)public <T> T convert(java.lang.Object object, java.lang.Class<T> instanceClass, java.lang.String... path)
JsonHelper
This is usefull to convert opan api "anyOf" objects into a defined DTO.
convert
in interface JsonHelper
T
- he type of the converted objectobject
- the json object (like a json native object or a map)instanceClass
- the class of the converted objectpath
- the pathpublic java.lang.Integer getInteger(java.lang.Object object, java.lang.String... path)
JsonHelper
for example:
object = { "someAttribute1": {"someAttribute2": {"aNumber": 10} } }
getInteger(object,"someAttribute1","someAttribute2","aNumber") will return 10
getInteger
in interface JsonHelper
object
- the objectpath
- the pathpublic java.lang.String getString(java.lang.Object object, java.lang.String... path)
JsonHelper
for example:
object = { "someAttribute1": {"someAttribute2": {"aString": "hello"} } }
getInteger(object,"someAttribute1","someAttribute2","aString") will return "hello"
getString
in interface JsonHelper
object
- the objectpath
- the pathpublic java.lang.Long getLong(java.lang.Object object, java.lang.String... path)
JsonHelper
for example:
object = { "someAttribute1": {"someAttribute2": {"aNumber": 10} } }
getInteger(object,"someAttribute1","someAttribute2","aNumber") will return 10
getLong
in interface JsonHelper
object
- the objectpath
- the pathpublic java.lang.Boolean getBoolean(java.lang.Object object, java.lang.String... path)
JsonHelper
for example:
object = { "someAttribute1": {"someAttribute2": {"aBoolean": true} } }
getInteger(object,"someAttribute1","someAttribute2","aBoolean") will return true
getBoolean
in interface JsonHelper
object
- the objectpath
- the pathpublic java.math.BigInteger getBigInteger(java.lang.Object object, java.lang.String... path)
JsonHelper
for example:
object = { "someAttribute1": {"someAttribute2": {"aBigInteger": "123"} } }
getBigInteger(object,"someAttribute1","someAttribute2","aBigInteger") will return 123
getBigInteger
in interface JsonHelper
object
- the objectpath
- the pathpublic boolean contains(java.lang.Object object, java.lang.String... path)
JsonHelper
contains
in interface JsonHelper
object
- the objectpath
- the pathpublic java.lang.Object getObject(java.lang.Object object, java.lang.String... path)
JsonHelper
getObject
in interface JsonHelper
object
- the objectpath
- the path