java.lang.Object
ch.ralscha.extdirectspring.util.JsonHandler
Object contains an
ObjectMapper and provides convenient methods.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TconvertValue(Object object, com.fasterxml.jackson.databind.JavaType toValueTypeRef) Converts one object into another.<T> TconvertValue(Object object, Class<T> clazz) Converts one object into another.com.fasterxml.jackson.databind.ObjectMapperreadValue(InputStream is, Class<Object> clazz) Converts a JSON string into an object.<T> TConverts a JSON string into an object.<T> TConverts a JSON string into an object.voidsetMapper(com.fasterxml.jackson.databind.ObjectMapper mapper) Sets a new instance ofObjectMapper.writeValueAsString(Object obj) Converts an object into a JSON string.writeValueAsString(Object obj, boolean indent) Converts an object into a JSON string.
-
Constructor Details
-
JsonHandler
public JsonHandler() -
JsonHandler
public JsonHandler(com.fasterxml.jackson.databind.ObjectMapper mapper)
-
-
Method Details
-
setMapper
public void setMapper(com.fasterxml.jackson.databind.ObjectMapper mapper) Sets a new instance ofObjectMapper.- Parameters:
mapper- a new object mapper. must not benull
-
getMapper
public com.fasterxml.jackson.databind.ObjectMapper getMapper()- Returns:
- the currently assigned
ObjectMapper
-
writeValueAsString
Converts an object into a JSON string. In case of an exception returns null and logs the exception.- Parameters:
obj- the source object- Returns:
- obj JSON string,
nullif an exception occurred
-
writeValueAsString
Converts an object into a JSON string. In case of an exceptions returns null and logs the exception.- Parameters:
obj- the source objectindent- if true JSON is written in a human readable format, if false JSON is written on one line- Returns:
- obj JSON string,
nullif an exception occurred
-
readValue
Converts a JSON string into an object. In case of an exception returns null and logs the exception.- Type Parameters:
T- type of the object to create- Parameters:
json- string with the JSONtypeReference-TypeReferenceinstance of the desired result typeTypeReference- Returns:
- the created object, null if there was an exception
-
readValue
Converts a JSON string into an object. In case of an exception returns null and logs the exception.- Type Parameters:
T- type of the object to create- Parameters:
json- string with the JSONclazz- class of object to create- Returns:
- the converted object, null if there is an exception
-
readValue
Converts a JSON string into an object. The input is read from an InputStream. In case of an exception returns null and logs the exception.- Parameters:
is- a InputStreamclazz- class of object to create- Returns:
- the converted object, null if there is an exception
-
convertValue
Converts one object into another.- Parameters:
object- the sourceclazz- the type of the target- Returns:
- the converted object
-
convertValue
Converts one object into another.- Parameters:
object- the sourcetoValueTypeRef- the type of the target- Returns:
- the converted object
-