public interface JsonHelper
Mappers should use the statically typed open API generated DTOs when possible. This helper should be used when there is no way of just using the DTOs. For example when processing "anyOf" kind of attributes.
This interface hides the json underline implementation like gson or jackson2.
Modifier and Type | Method and Description |
---|---|
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.
|
java.lang.String print(java.lang.Object object)
object
- the object (json native object, MAP or DTO)java.lang.String prettyPrint(java.lang.Object object)
object
- the object (json native object, MAP or DTO)java.lang.Object parse(java.lang.String string)
string
- the json string<T> java.util.List<T> parseList(java.lang.String string, java.lang.Class<T> clazz)
T
- the type of the parsed objectstring
- the json stringclazz
- the class of the parsed object<T> T parse(java.lang.String string, java.lang.Class<T> clazz)
T
- the type of the parsed objectstring
- the json stringclazz
- the class of the parsed object<T> T convert(java.lang.Object object, java.lang.Class<T> instanceClass, java.lang.String... path)
This is usefull to convert opan api "anyOf" objects into a defined DTO.
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 pathjava.lang.Integer getInteger(java.lang.Object object, java.lang.String... path)
for example:
object = { "someAttribute1": {"someAttribute2": {"aNumber": 10} } }
getInteger(object,"someAttribute1","someAttribute2","aNumber") will return 10
object
- the objectpath
- the pathjava.lang.Long getLong(java.lang.Object object, java.lang.String... path)
for example:
object = { "someAttribute1": {"someAttribute2": {"aNumber": 10} } }
getInteger(object,"someAttribute1","someAttribute2","aNumber") will return 10
object
- the objectpath
- the pathjava.lang.String getString(java.lang.Object object, java.lang.String... path)
for example:
object = { "someAttribute1": {"someAttribute2": {"aString": "hello"} } }
getInteger(object,"someAttribute1","someAttribute2","aString") will return "hello"
object
- the objectpath
- the pathjava.lang.Boolean getBoolean(java.lang.Object object, java.lang.String... path)
for example:
object = { "someAttribute1": {"someAttribute2": {"aBoolean": true} } }
getInteger(object,"someAttribute1","someAttribute2","aBoolean") will return true
object
- the objectpath
- the pathjava.math.BigInteger getBigInteger(java.lang.Object object, java.lang.String... path)
for example:
object = { "someAttribute1": {"someAttribute2": {"aBigInteger": "123"} } }
getBigInteger(object,"someAttribute1","someAttribute2","aBigInteger") will return 123
object
- the objectpath
- the pathboolean contains(java.lang.Object object, java.lang.String... path)
object
- the objectpath
- the pathjava.lang.Object getObject(java.lang.Object object, java.lang.String... path)
object
- the objectpath
- the path