Interface IFastJsonConverter
- All Known Implementing Classes:
DefaultFastJsonConverter
public interface IFastJsonConverter
Interface for a handler that performs serialization and deserialization via
JSON
. Instances should add the
appropriate configuration, such as custom serializers etc.- Since:
- 7.0.0
- Author:
- XIMA MEDIA GmbH
-
Method Summary
Modifier and TypeMethodDescriptiondefault <T> List<T>
parseJavaArray
(com.alibaba.fastjson.JSONArray json, Class<T> clazz) 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
(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.default <T> List<T>
parseJavaArray
(String json, Class<T> clazz) Deserializes a JSON string into aList
of Java objects of a particular class.<T> List<T>
parseJavaArray
(String json, Type type) Deserializes a JSON string into aList
of Java objects of a particular class.default <T> T
parseJavaObject
(com.alibaba.fastjson.JSONObject json, Class<T> clazz) Creates an instance of the given class and populates it with the data from the given JSON object.<T> T
parseJavaObject
(com.alibaba.fastjson.JSONObject json, Type type) Creates an instance of the given class and populates it with the data from the given JSON object.default <T> T
parseJavaObject
(String json, Class<T> clazz) Deserializes a JSON string into a Java object of a particular class.<T> T
parseJavaObject
(String json, Type type) Deserializes a JSON string into a Java object of a particular class.com.alibaba.fastjson.JSONArray
parseJsonArray
(String json) Takes a JSON string and parses it into a JSON array.com.alibaba.fastjson.JSONObject
parseJsonObject
(String json) Takes a JSON string and parses it into a JSON object.com.alibaba.fastjson.JSONObject
toJsonObject
(Object data) Serializes the given instance to a JSON object.toJsonString
(Object data) Deprecated.default String
toJsonString
(Object data, IFastJsonSerializeOptions options) Serializes the given instance to a JSON string.
-
Method Details
-
parseJavaArray
default <T> List<T> parseJavaArray(com.alibaba.fastjson.JSONArray json, Class<T> clazz) throws FastJsonException Creates a new list and for each entry in the given JSON array, adds an object with the data from that entry.- 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.clazz
- 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
Creates a new list and for each entry in the given JSON array, adds an object with the data from that entry.- 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
Deserializes a JSON string into aList
of Java objects of a particular class.- 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.
-
parseJavaArray
Deserializes a JSON string into aList
of Java objects of a particular class.- 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.type
- 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
default <T> T parseJavaObject(com.alibaba.fastjson.JSONObject json, Class<T> clazz) throws FastJsonException Creates an instance of the given class and populates it with the data from the given JSON object.- 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
Creates an instance of the given class and populates it with the data from the given JSON object.- Type Parameters:
T
- Type of the class to create.- Parameters:
json
- JSON object with the data to set on the newly created instance.type
- 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
Deserializes a JSON string into a Java object of a particular class.- 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.
-
parseJavaObject
Deserializes a JSON string into a Java object of a particular class.- 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.type
- 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
Takes a JSON string and parses it into a JSON array.- 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
Takes a JSON string and parses it into a JSON object.- 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
Serializes the given instance to a JSON object.- 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
Deprecated.UsetoJsonString(Object, IFastJsonSerializeOptions.DEFAULT)
, but prefertoJsonString(Object, IFastJsonSerializeOptions.ESCAPE_FOR_HTML_SCRIPT_TAG)
.Serializes the given instance to a JSON string.- 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.
-
toJsonString
default String toJsonString(Object data, IFastJsonSerializeOptions options) throws FastJsonException Serializes the given instance to a JSON string.- Parameters:
data
- The data object to serialize.options
- Options for the serialization process.- Returns:
- A JSON string that represents the serialized form of the given data.
- Throws:
FastJsonException
- When the JSON could not be serialized.
-
toJsonString(Object, IFastJsonSerializeOptions.DEFAULT)
, but prefertoJsonString(Object, IFastJsonSerializeOptions.ESCAPE_FOR_HTML_SCRIPT_TAG)
.