Package com.studerw.tda.parse
Class DefaultMapper
java.lang.Object
com.studerw.tda.parse.DefaultMapper
Convert between Java pojos and JSON. This class is thread safe.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
fromJson
(InputStream in, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) Convert object from JSON to POJO.static <T> T
fromJson
(InputStream in, Class<T> clazz) Convert object from JSON to POJO.static <T> T
Convert object from JSON to POJOstatic String
Convert object to JSON string.
-
Constructor Details
-
DefaultMapper
public DefaultMapper()
-
-
Method Details
-
toJson
Convert object to JSON string. UseUtils.prettyFormat(String)
to pretty format the returned JSON string.- Parameters:
object
- Java POJO to serialize into JSON- Returns:
- JSON representation of the object
-
fromJson
Convert object from JSON to POJO- Type Parameters:
T
- the type to marshall- Parameters:
json
- string of jsonclazz
- the class type- Returns:
- a deserialized java POJO
-
fromJson
Convert object from JSON to POJO.- Type Parameters:
T
- the type to marshall- Parameters:
in
- InputStream of json, guaranteed to be closed upon return.clazz
- the class type- Returns:
- a deserialized java POJO
-
fromJson
public static <T> T fromJson(InputStream in, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) Convert object from JSON to POJO.- Type Parameters:
T
- the type to marshall- Parameters:
in
- InputStream of json, guaranteed to be closed upon return.typeReference
- JacksonTypeReference
of the pojo to map- Returns:
- a deserialized java POJO
-