|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.json.JSONSerializer
public class 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.
Use the provided property setters before calling toJava()
.
Field Summary | |
---|---|
static int |
MODE_LIST
|
static int |
MODE_OBJECT_ARRAY
|
Constructor Summary | |
---|---|
JSONSerializer()
Default constructor |
|
JSONSerializer(Class rootClass,
Map classMap,
int arrayMode)
Constructs a new JSONSerializer with specific values for conversion. |
Method Summary | |
---|---|
int |
getArrayMode()
Returns the current array mode conversion |
Map |
getClassMap()
Returns the current attribute/class Map |
Class |
getRootClass()
Returns the current root Class. |
void |
reset()
Resets this serializer to default values. |
void |
setArrayMode(int arrayMode)
Sets the current array mode for conversion. |
void |
setClassMap(Map classMap)
Sets the current attribute/Class Map |
void |
setRootClass(Class rootClass)
Sets the current root Class |
Object |
toJava(JSON json)
Transform a JSON value to a java object. |
static JSON |
toJSON(Object object)
Creates a JSONObject, JSONArray or a JSONNull from object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int MODE_LIST
public static final int MODE_OBJECT_ARRAY
Constructor Detail |
---|
public JSONSerializer()
public JSONSerializer(Class rootClass, Map classMap, int arrayMode)
rootClass
- the target class for conversionclassMap
- Map of classes, every key identifies a property or a
regexparrayMode
- array mode for conversion, either MODE_OBJECT_ARRAY or
MODE_LISTMethod Detail |
---|
public static JSON toJSON(Object object)
object
- any java Object
JSONException
- if the object can not be convertedpublic int getArrayMode()
public Map getClassMap()
public Class getRootClass()
public void reset()
public void setArrayMode(int arrayMode)
arrayMode
- array mode for conversionpublic void setClassMap(Map classMap)
classMap
- a Map of classes, every key identifies a property or a
regexppublic void setRootClass(Class rootClass)
rootClass
- the target class for conversionpublic Object toJava(JSON json)
json
- a JSON value
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |