Package org.kordamp.json
Class JSONSerializer
java.lang.Object
org.kordamp.json.JSONSerializer
Transforms java objects into JSON and back.
Transformation from java to JSON is pretty straightforward, but the other way around needs certain configuration, otherwise the java objects produced will be DynaBeans and Lists, because the JSON notation does not carry any information on java classes.
Transformation from java to JSON is pretty straightforward, but the other way around needs certain configuration, otherwise the java objects produced will be DynaBeans and Lists, because the JSON notation does not carry any information on java classes.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Object
Transform a JSON value to a java object.
Depending on the configured values for conversion this will return a DynaBean, a bean, a List, or and array.static Object
toJava
(JSON json, JsonConfig jsonConfig) Transform a JSON value to a java object.
Depending on the configured values for conversion this will return a DynaBean, a bean, a List, or and array.static JSON
Creates a JSONObject, JSONArray or a JSONNull from object.
Accepts JSON formatted strings, Maps, arrays, Collections, DynaBeans and JavaBeans.static JSON
toJSON
(Object object, JsonConfig jsonConfig) Creates a JSONObject, JSONArray or a JSONNull from object.
Accepts JSON formatted strings, Maps, arrays, Collections, DynaBeans and JavaBeans.private static JSON
toJSON
(String string, JsonConfig jsonConfig) Creates a JSONObject, JSONArray or a JSONNull from a JSONString.private static JSON
toJSON
(JSONString string, JsonConfig jsonConfig) Creates a JSONObject, JSONArray or a JSONNull from a JSONString.
-
Constructor Details
-
JSONSerializer
public JSONSerializer()
-
-
Method Details
-
toJava
Transform a JSON value to a java object.
Depending on the configured values for conversion this will return a DynaBean, a bean, a List, or and array.- Parameters:
json
- a JSON value- Returns:
- depends on the nature of the source object (JSONObject, JSONArray, JSONNull).
-
toJava
Transform a JSON value to a java object.
Depending on the configured values for conversion this will return a DynaBean, a bean, a List, or and array.- Parameters:
json
- a JSON valuejsonConfig
- additional configuration- Returns:
- depends on the nature of the source object (JSONObject, JSONArray, JSONNull) and the configured rootClass, classMap and arrayMode
-
toJSON
Creates a JSONObject, JSONArray or a JSONNull from object.
Accepts JSON formatted strings, Maps, arrays, Collections, DynaBeans and JavaBeans.- Parameters:
object
- any java Object- Throws:
JSONException
- if the object can not be converted
-
toJSON
Creates a JSONObject, JSONArray or a JSONNull from object.
Accepts JSON formatted strings, Maps, arrays, Collections, DynaBeans and JavaBeans.- Parameters:
object
- any java ObjectjsonConfig
- additional configuration- Throws:
JSONException
- if the object can not be converted
-
toJSON
Creates a JSONObject, JSONArray or a JSONNull from a JSONString.- Throws:
JSONException
- if the string is not a valid JSON string
-
toJSON
Creates a JSONObject, JSONArray or a JSONNull from a JSONString.- Throws:
JSONException
- if the string is not a valid JSON string
-