|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.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(java.lang.Class rootClass,
java.util.Map classMap,
int arrayMode)
Constructs a new JSONSerializer with specific values for conversion. |
Method Summary | |
---|---|
int |
getArrayMode()
Returns the current array mode conversion |
java.util.Map |
getClassMap()
Returns the current attribute/class Map |
java.lang.Class |
getRootClass()
Returns the current root Class. |
void |
reset()
Resets this serializer to default values. rootClass = null classMap = null arrayMode = MODE_LIST |
void |
setArrayMode(int arrayMode)
Sets the current array mode for conversion. If the value is not MODE_LIST neither MODE_OBJECT_ARRAY, then MODE_LIST will be used. |
void |
setClassMap(java.util.Map classMap)
Sets the current attribute/Class Map |
void |
setRootClass(java.lang.Class rootClass)
Sets the current root Class |
java.lang.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 JSON |
toJSON(java.lang.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(java.lang.Class rootClass, java.util.Map classMap, int arrayMode)
rootClass
- classMap
- arrayMode
- Method Detail |
---|
public static JSON toJSON(java.lang.Object object)
JSONException
- is the object can not be convertedpublic int getArrayMode()
public java.util.Map getClassMap()
public java.lang.Class getRootClass()
public void reset()
public void setArrayMode(int arrayMode)
arrayMode
- public void setClassMap(java.util.Map classMap)
classMap
- public void setRootClass(java.lang.Class rootClass)
rootClass
- public java.lang.Object toJava(JSON json)
json
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |