public class JsonUtils
extends java.lang.Object
| Constructor and Description |
|---|
JsonUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
readObjectFromJsonString(java.lang.String jsonString,
java.lang.Class<T> type)
This is a helper method that invokes
readObjectFromJsonString(String, Class, boolean) with the second parameter
set to false. |
static <T> T |
readObjectFromJsonString(java.lang.String jsonString,
java.lang.Class<T> type,
boolean enableDefaultTyping)
This method reads (deserializes) JSON string into specific Object type with option to allow or disallow default typing.
|
static java.lang.String |
writeObjectToJsonString(java.lang.Object object)
This is a helper method that invokes
writeObjectToJsonString(Object, boolean) with the second parameter set to
false. |
static java.lang.String |
writeObjectToJsonString(java.lang.Object object,
boolean enableDefaultTyping)
This method writes (serializes) an Object into JSON String with option to allow or disallow default typing.
|
public static java.lang.String writeObjectToJsonString(java.lang.Object object,
boolean enableDefaultTyping)
throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.databind.jsontype.DefaultBaseTypeLimitingValidator.
If you are not familiar with default typing concept in JASON-JACKSON library than simply use helper method
writeObjectToJsonString(Object). It will do the job in most casesobject - an Object to be deserializedenableDefaultTyping - boolean flag that determines if default typing is allowedcom.fasterxml.jackson.core.JsonProcessingExceptionwriteObjectToJsonString(Object)public static java.lang.String writeObjectToJsonString(java.lang.Object object)
throws com.fasterxml.jackson.core.JsonProcessingException
writeObjectToJsonString(Object, boolean) with the second parameter set to
false. In most cases (when you don't need to worry about default typing) this method should be used instead of
invoking method writeObjectToJsonString(Object, boolean)object - an Object to be deserializedcom.fasterxml.jackson.core.JsonProcessingExceptionpublic static <T> T readObjectFromJsonString(java.lang.String jsonString,
java.lang.Class<T> type,
boolean enableDefaultTyping)
throws java.io.IOException
com.fasterxml.jackson.databind.jsontype.DefaultBaseTypeLimitingValidator.
If you are not familiar with default typing concept in JASON-JACKSON library than simply use helper method
readObjectFromJsonString(String, Class). It will do the job in most cases
Just a short example: Assume that there is a class Person and an instance of this class was serialized to JSON
String. And now there is a need to deserialize it back. So the code to do so would look like this:
Person person = JSONUtils.readObjectFromJsonString(jsonString, Person.class, false);
T - A class instance of which will be returned if deserialization succeeds.jsonString - JSON string to be deserializedtype - deserialization target classenableDefaultTyping - boolean flag that determines if default typing is allowedjava.io.IOExceptionreadObjectFromJsonString(String, Class)public static <T> T readObjectFromJsonString(java.lang.String jsonString,
java.lang.Class<T> type)
throws java.io.IOException
readObjectFromJsonString(String, Class, boolean) with the second parameter
set to false. In most cases (when you don't need to worry about default typing) this method should be used instead
of invoking method readObjectFromJsonString(String, Class, boolean)
Just a short example: Assume that there is a class Person and an instance of this class was serialized to JSON
String. And now there is a need to deserialize it back. So the code to do so would look like this:
Person person = JSONUtils.readObjectFromJsonString(jsonString, Person.class);
T - A class instance of which will be returned if deserialization succeeds.jsonString - JSON string to be deserializedtype - deserialization target classjava.io.IOException