net.sf.json
Class JSONSerializer

java.lang.Object
  extended by net.sf.json.JSONSerializer

public class JSONSerializer
extends Object

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.

Author:
Andres Almiray

Constructor Summary
JSONSerializer()
           
 
Method Summary
static Object toJava(JSON json)
          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 toJSON(Object object)
          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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONSerializer

public JSONSerializer()
Method Detail

toJava

public static Object toJava(JSON json)
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

public 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.

Parameters:
json - a JSON value
jsonConfig - additional configuration
Returns:
depends on the nature of the source object (JSONObject, JSONArray, JSONNull) and the configured rootClass, classMap and arrayMode

toJSON

public static JSON toJSON(Object object)
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

public 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.

Parameters:
object - any java Object
jsonConfig - additional configuration
Throws:
JSONException - if the object can not be converted