Package de.xima.fc.fastjson
Class DefaultFastJsonConverter
- java.lang.Object
-
- de.xima.fc.fastjson.DefaultFastJsonConverter
-
- All Implemented Interfaces:
IFastJsonConverter
public final class DefaultFastJsonConverter extends Object implements IFastJsonConverter
Default implementation ofIFastJsonConverterthat does not add any custom serializers etc.- Since:
- 7.0.0
- Author:
- XIMA MEDIA GmbH
-
-
Field Summary
Fields Modifier and Type Field Description static IFastJsonConverterINSTANCEThe immutable, thread-safe instance of the default fast JSON converter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static IFastJsonConverterforClassLoader(ClassLoader loader)static IFastJsonConverterforClassLoaderCached(ClassLoader loader)Same asforClassLoader, but reuses created instances if possible.<T> List<T>parseJavaArray(com.alibaba.fastjson.JSONArray json, Type type)Creates a new list and for each entry in the given JSON array, adds an object with the data from that entry.<T> List<T>parseJavaArray(String json, Type clazz)Deserializes a JSON string into aListof Java objects of a particular class.<T> TparseJavaObject(com.alibaba.fastjson.JSONObject json, Type clazz)Creates an instance of the given class and populates it with the data from the given JSON object.<T> TparseJavaObject(String json, Type clazz)Deserializes a JSON string into a Java object of a particular class.com.alibaba.fastjson.JSONArrayparseJsonArray(String json)Takes a JSON string and parses it into a JSON array.com.alibaba.fastjson.JSONObjectparseJsonObject(String json)Takes a JSON string and parses it into a JSON object.com.alibaba.fastjson.JSONObjecttoJsonObject(Object data)Serializes the given instance to a JSON object.StringtoJsonString(Object data)Serializes the given instance to a JSON string.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.xima.fc.interfaces.plugin.retval.workflow.IFastJsonConverter
parseJavaArray, parseJavaArray, parseJavaObject, parseJavaObject
-
-
-
-
Field Detail
-
INSTANCE
public static IFastJsonConverter INSTANCE
The immutable, thread-safe instance of the default fast JSON converter.
-
-
Method Detail
-
parseJavaArray
public <T> List<T> parseJavaArray(com.alibaba.fastjson.JSONArray json, Type type) throws FastJsonException
Description copied from interface:IFastJsonConverterCreates a new list and for each entry in the given JSON array, adds an object with the data from that entry.- Specified by:
parseJavaArrayin interfaceIFastJsonConverter- Type Parameters:
T- Type of the list items to create.- Parameters:
json- JSONArray to convert. The items in this array are expected to be JSON objects.type- Class of the items to create.- Returns:
- A new list, populated with the converted items from the given JSON array.
- Throws:
FastJsonException- When the JSON could not be parsed.
-
parseJavaArray
public <T> List<T> parseJavaArray(String json, Type clazz) throws FastJsonException
Description copied from interface:IFastJsonConverterDeserializes a JSON string into aListof Java objects of a particular class.- Specified by:
parseJavaArrayin interfaceIFastJsonConverter- Type Parameters:
T- Type of the list items.- Parameters:
json- JSON string to parse. This is assumed to represent a JSON array of JSON objects.clazz- Class of the items in the JSON array.- Returns:
- A list with the deserialized objects from the given JSON array.
- Throws:
FastJsonException- When the JSON could not be parsed.
-
parseJavaObject
public <T> T parseJavaObject(com.alibaba.fastjson.JSONObject json, Type clazz) throws FastJsonExceptionDescription copied from interface:IFastJsonConverterCreates an instance of the given class and populates it with the data from the given JSON object.- Specified by:
parseJavaObjectin interfaceIFastJsonConverter- Type Parameters:
T- Type of the class to create.- Parameters:
json- JSON object with the data to set on the newly created instance.clazz- Class of the instance to create.- Returns:
- A new instance of the given class, with the data from the given JSON object.
- Throws:
FastJsonException- When the JSON could not be parsed.
-
parseJavaObject
public <T> T parseJavaObject(String json, Type clazz) throws FastJsonException
Description copied from interface:IFastJsonConverterDeserializes a JSON string into a Java object of a particular class.- Specified by:
parseJavaObjectin interfaceIFastJsonConverter- Type Parameters:
T- Type of the class to create from the JSON string.- Parameters:
json- JSON string to parse. This is assumed to represent a JSON object.clazz- Class to create from the JSON string.- Returns:
- The deserialized object with the data from the JSON string.
- Throws:
FastJsonException- When the JSON could not be parsed.
-
parseJsonArray
public com.alibaba.fastjson.JSONArray parseJsonArray(String json) throws FastJsonException
Description copied from interface:IFastJsonConverterTakes a JSON string and parses it into a JSON array.- Specified by:
parseJsonArrayin interfaceIFastJsonConverter- Parameters:
json- JSON string to parse. This is assumed to represent a JSON array.- Returns:
- The parsed JSON array.
- Throws:
FastJsonException- When the JSON could not be parsed.
-
parseJsonObject
public com.alibaba.fastjson.JSONObject parseJsonObject(String json) throws FastJsonException
Description copied from interface:IFastJsonConverterTakes a JSON string and parses it into a JSON object.- Specified by:
parseJsonObjectin interfaceIFastJsonConverter- Parameters:
json- JSON string to parse. This is assumed to represent a JSON object.- Returns:
- The parsed JSON object.
- Throws:
FastJsonException- When the JSON could not be parsed.
-
toJsonObject
public com.alibaba.fastjson.JSONObject toJsonObject(Object data) throws FastJsonException
Description copied from interface:IFastJsonConverterSerializes the given instance to a JSON object.- Specified by:
toJsonObjectin interfaceIFastJsonConverter- Parameters:
data- The data object to serialize.- Returns:
- A JSON object with the data from the given object.
- Throws:
FastJsonException- When the JSON could not be serialized.
-
toJsonString
public String toJsonString(Object data) throws FastJsonException
Description copied from interface:IFastJsonConverterSerializes the given instance to a JSON string.- Specified by:
toJsonStringin interfaceIFastJsonConverter- Parameters:
data- The data object to serialize.- Returns:
- A JSON string that represents the serialized form of the given data.
- Throws:
FastJsonException- When the JSON could not be serialized.
-
forClassLoader
public static IFastJsonConverter forClassLoader(ClassLoader loader)
- Parameters:
loader- Class loader to use for locating classes during deserialization.- Returns:
- An (effectively) immutable
IFastJsonConverterinstance with the given class loader. - Throws:
NullPointerException- Whenloaderisnull.
-
forClassLoaderCached
public static IFastJsonConverter forClassLoaderCached(ClassLoader loader)
Same asforClassLoader, but reuses created instances if possible. Not that since the returned converter is effectively immutable, there is no functional difference between this method andforClassLoader.- Parameters:
loader- Class loader to use for locating classes during deserialization.- Returns:
- An (effectively) immutable
IFastJsonConverterinstance with the given class loader. - Throws:
NullPointerException- Whenloaderisnull.
-
-