Class JSONDeserializer
java.lang.Object
nonapi.io.github.classgraph.json.JSONDeserializer
Fast, lightweight Java object to JSON serializer, and JSON to Java object deserializer. Handles cycles in the
object graph by inserting reference ids.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TdeserializeObject(Class<T> expectedType, String json) Deserialize JSON to a new object graph, with the root object of the specified expected type.static <T> TdeserializeObject(Class<T> expectedType, String json, ReflectionUtils reflectionUtils) Deserialize JSON to a new object graph, with the root object of the specified expected type.static voiddeserializeToField(Object containingObject, String fieldName, String json) Deserialize JSON to a new object graph, with the root object of the specified expected type, and store the root object in the named field of the given containing object.static voiddeserializeToField(Object containingObject, String fieldName, String json, nonapi.io.github.classgraph.json.ClassFieldCache classFieldCache) Deserialize JSON to a new object graph, with the root object of the specified expected type, and store the root object in the named field of the given containing object.static voiddeserializeToField(Object containingObject, String fieldName, String json, ReflectionUtils reflectionUtils) Deserialize JSON to a new object graph, with the root object of the specified expected type, and store the root object in the named field of the given containing object.
-
Method Details
-
deserializeObject
public static <T> T deserializeObject(Class<T> expectedType, String json, ReflectionUtils reflectionUtils) throws IllegalArgumentException Deserialize JSON to a new object graph, with the root object of the specified expected type. Does not work for generic types, since it is not possible to obtain the generic type of a Class reference.- Type Parameters:
T- The type that the JSON should conform to.- Parameters:
expectedType- The class reference for the type that the JSON should conform to.json- the JSON string to deserialize.- Returns:
- The object graph after deserialization.
- Throws:
IllegalArgumentException- If anything goes wrong during deserialization.
-
deserializeObject
public static <T> T deserializeObject(Class<T> expectedType, String json) throws IllegalArgumentException Deserialize JSON to a new object graph, with the root object of the specified expected type. Does not work for generic types, since it is not possible to obtain the generic type of a Class reference.- Type Parameters:
T- The type that the JSON should conform to.- Parameters:
expectedType- The class reference for the type that the JSON should conform to.json- the JSON string to deserialize.- Returns:
- The object graph after deserialization.
- Throws:
IllegalArgumentException- If anything goes wrong during deserialization.
-
deserializeToField
public static void deserializeToField(Object containingObject, String fieldName, String json, nonapi.io.github.classgraph.json.ClassFieldCache classFieldCache) throws IllegalArgumentException Deserialize JSON to a new object graph, with the root object of the specified expected type, and store the root object in the named field of the given containing object. Works for generic types, since it is possible to obtain the generic type of a field.- Parameters:
containingObject- The object containing the named field to deserialize the object graph into.fieldName- The name of the field to set with the result.json- the JSON string to deserialize.classFieldCache- The class field cache. Reusing this cache will increase the speed if many JSON documents of the same type need to be parsed.- Throws:
IllegalArgumentException- If anything goes wrong during deserialization.
-
deserializeToField
public static void deserializeToField(Object containingObject, String fieldName, String json, ReflectionUtils reflectionUtils) throws IllegalArgumentException Deserialize JSON to a new object graph, with the root object of the specified expected type, and store the root object in the named field of the given containing object. Works for generic types, since it is possible to obtain the generic type of a field.- Parameters:
containingObject- The object containing the named field to deserialize the object graph into.fieldName- The name of the field to set with the result.json- the JSON string to deserialize.- Throws:
IllegalArgumentException- If anything goes wrong during deserialization.
-
deserializeToField
public static void deserializeToField(Object containingObject, String fieldName, String json) throws IllegalArgumentException Deserialize JSON to a new object graph, with the root object of the specified expected type, and store the root object in the named field of the given containing object. Works for generic types, since it is possible to obtain the generic type of a field.- Parameters:
containingObject- The object containing the named field to deserialize the object graph into.fieldName- The name of the field to set with the result.json- the JSON string to deserialize.- Throws:
IllegalArgumentException- If anything goes wrong during deserialization.
-