Class JSONMarshall
- java.lang.Object
-
- com.sdicons.json.serializer.marshall.JSONMarshall
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ERR_MISSINGATTR
static java.lang.String
ERR_MISSINGATTRVAL
static java.lang.String
ERR_MISSINGSTRING
private long
idCounter
private static java.lang.String
IDPREFIX
private HelperRepository<MarshallHelper>
repo
static java.lang.String
RNDR_ARR
static java.lang.String
RNDR_ATTR_CLASS
static java.lang.String
RNDR_ATTR_ID
static java.lang.String
RNDR_ATTR_KIND
static java.lang.String
RNDR_ATTR_REF
static java.lang.String
RNDR_ATTR_TYPE
static java.lang.String
RNDR_ATTR_VALUE
static java.lang.String
RNDR_NULL
static java.lang.String
RNDR_OBJ
static java.lang.String
RNDR_OBJREF
static java.lang.String
RNDR_PRIM
static java.lang.String
RNDR_PRTITYP_BOOLEAN
static java.lang.String
RNDR_PRTITYP_BYTE
static java.lang.String
RNDR_PRTITYP_CHAR
static java.lang.String
RNDR_PRTITYP_DOUBLE
static java.lang.String
RNDR_PRTITYP_FLOAT
static java.lang.String
RNDR_PRTITYP_INT
static java.lang.String
RNDR_PRTITYP_LONG
static java.lang.String
RNDR_PRTITYP_SHORT
-
Constructor Summary
Constructors Constructor Description JSONMarshall()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addHelper(MarshallHelper aHelper)
Add custom helper class.private java.lang.String
generateId()
JSONObject
marshall(boolean aValue)
Convert a boolean primitive to JSON.JSONObject
marshall(byte aValue)
Convert a byte primitive to JSON.JSONObject
marshall(char aValue)
Convert a char primitive to JSON.JSONObject
marshall(double aValue)
Convert a double primitive to JSON.JSONObject
marshall(float aValue)
Convert a float primitive to JSON.JSONObject
marshall(int aValue)
Convert an int primitive to JSON.JSONObject
marshall(long aValue)
Convert a long primitive to JSON.JSONObject
marshall(short aValue)
Convert a short primitive to JSON.JSONObject
marshall(java.lang.Object aObj)
Convert a Java object to JSON.JSONObject
marshallImpl(java.lang.Object aObj, java.util.HashMap aPool)
private JSONObject
marshallImplArray(java.lang.Object aObj, java.util.HashMap aPool)
private JSONObject
marshallImplObject(java.lang.Object aObj, java.lang.String aObjId, java.lang.Class aObjClass, java.lang.String aObjClassName, java.util.HashMap aPool)
private JSONObject
marshallPrimitive(java.lang.String aType, java.lang.String aValue)
static void
requireStringAttribute(JSONObject aElement, java.lang.String anAttribute)
MarshallValue
unmarshall(JSONObject aElement)
Convert a JSON representation to the Java primitive or reference.java.lang.Object
unmarshallImpl(JSONObject aElement, java.util.HashMap aObjectPool)
private java.lang.Object
unmarshallImplPrimitive(JSONObject aElement)
void
useJavaBeanAccess()
The objects that fall back on the general object helper will be serialized by using their JavaBean properties.void
usePojoAccess()
The objects that fall back on the general object helper will be serialized by using their fields directly.
-
-
-
Field Detail
-
IDPREFIX
private static final java.lang.String IDPREFIX
- See Also:
- Constant Field Values
-
idCounter
private long idCounter
-
RNDR_NULL
public static final java.lang.String RNDR_NULL
- See Also:
- Constant Field Values
-
RNDR_OBJ
public static final java.lang.String RNDR_OBJ
- See Also:
- Constant Field Values
-
RNDR_OBJREF
public static final java.lang.String RNDR_OBJREF
- See Also:
- Constant Field Values
-
RNDR_PRIM
public static final java.lang.String RNDR_PRIM
- See Also:
- Constant Field Values
-
RNDR_ARR
public static final java.lang.String RNDR_ARR
- See Also:
- Constant Field Values
-
RNDR_ATTR_ID
public static final java.lang.String RNDR_ATTR_ID
- See Also:
- Constant Field Values
-
RNDR_ATTR_KIND
public static final java.lang.String RNDR_ATTR_KIND
- See Also:
- Constant Field Values
-
RNDR_ATTR_TYPE
public static final java.lang.String RNDR_ATTR_TYPE
- See Also:
- Constant Field Values
-
RNDR_ATTR_VALUE
public static final java.lang.String RNDR_ATTR_VALUE
- See Also:
- Constant Field Values
-
RNDR_ATTR_CLASS
public static final java.lang.String RNDR_ATTR_CLASS
- See Also:
- Constant Field Values
-
RNDR_ATTR_REF
public static final java.lang.String RNDR_ATTR_REF
- See Also:
- Constant Field Values
-
RNDR_PRTITYP_BOOLEAN
public static final java.lang.String RNDR_PRTITYP_BOOLEAN
- See Also:
- Constant Field Values
-
RNDR_PRTITYP_BYTE
public static final java.lang.String RNDR_PRTITYP_BYTE
- See Also:
- Constant Field Values
-
RNDR_PRTITYP_CHAR
public static final java.lang.String RNDR_PRTITYP_CHAR
- See Also:
- Constant Field Values
-
RNDR_PRTITYP_SHORT
public static final java.lang.String RNDR_PRTITYP_SHORT
- See Also:
- Constant Field Values
-
RNDR_PRTITYP_INT
public static final java.lang.String RNDR_PRTITYP_INT
- See Also:
- Constant Field Values
-
RNDR_PRTITYP_LONG
public static final java.lang.String RNDR_PRTITYP_LONG
- See Also:
- Constant Field Values
-
RNDR_PRTITYP_FLOAT
public static final java.lang.String RNDR_PRTITYP_FLOAT
- See Also:
- Constant Field Values
-
RNDR_PRTITYP_DOUBLE
public static final java.lang.String RNDR_PRTITYP_DOUBLE
- See Also:
- Constant Field Values
-
ERR_MISSINGATTR
public static final java.lang.String ERR_MISSINGATTR
- See Also:
- Constant Field Values
-
ERR_MISSINGATTRVAL
public static final java.lang.String ERR_MISSINGATTRVAL
- See Also:
- Constant Field Values
-
ERR_MISSINGSTRING
public static final java.lang.String ERR_MISSINGSTRING
- See Also:
- Constant Field Values
-
repo
private HelperRepository<MarshallHelper> repo
-
-
Method Detail
-
marshall
public JSONObject marshall(boolean aValue)
Description copied from interface:Marshall
Convert a boolean primitive to JSON.
-
marshall
public JSONObject marshall(byte aValue)
Description copied from interface:Marshall
Convert a byte primitive to JSON.
-
marshall
public JSONObject marshall(short aValue)
Description copied from interface:Marshall
Convert a short primitive to JSON.
-
marshall
public JSONObject marshall(char aValue)
Description copied from interface:Marshall
Convert a char primitive to JSON.
-
marshall
public JSONObject marshall(int aValue)
Description copied from interface:Marshall
Convert an int primitive to JSON.
-
marshall
public JSONObject marshall(long aValue)
Description copied from interface:Marshall
Convert a long primitive to JSON.
-
marshall
public JSONObject marshall(float aValue)
Description copied from interface:Marshall
Convert a float primitive to JSON.
-
marshall
public JSONObject marshall(double aValue)
Description copied from interface:Marshall
Convert a double primitive to JSON.
-
marshallPrimitive
private JSONObject marshallPrimitive(java.lang.String aType, java.lang.String aValue)
-
marshall
public JSONObject marshall(java.lang.Object aObj) throws MarshallException
Description copied from interface:Marshall
Convert a Java object to JSON.- Specified by:
marshall
in interfaceMarshall
- Returns:
- The JSON representation of the Java object.
- Throws:
MarshallException
- An error occured while converting the Java object to JSON.
-
marshallImpl
public JSONObject marshallImpl(java.lang.Object aObj, java.util.HashMap aPool) throws MarshallException
- Throws:
MarshallException
-
marshallImplArray
private JSONObject marshallImplArray(java.lang.Object aObj, java.util.HashMap aPool) throws MarshallException
- Throws:
MarshallException
-
marshallImplObject
private JSONObject marshallImplObject(java.lang.Object aObj, java.lang.String aObjId, java.lang.Class aObjClass, java.lang.String aObjClassName, java.util.HashMap aPool) throws MarshallException
- Throws:
MarshallException
-
generateId
private java.lang.String generateId()
-
unmarshall
public MarshallValue unmarshall(JSONObject aElement) throws MarshallException
Description copied from interface:Marshall
Convert a JSON representation to the Java primitive or reference.- Specified by:
unmarshall
in interfaceMarshall
- Returns:
- The Java representation of the JSON. This value can represent a Java primitive value or it can represent a Java reference.
- Throws:
MarshallException
- An error occured while trying to convert the JSON representation into a Java representation.
-
unmarshallImpl
public java.lang.Object unmarshallImpl(JSONObject aElement, java.util.HashMap aObjectPool) throws MarshallException
- Throws:
MarshallException
-
unmarshallImplPrimitive
private java.lang.Object unmarshallImplPrimitive(JSONObject aElement) throws MarshallException
- Throws:
MarshallException
-
requireStringAttribute
public static void requireStringAttribute(JSONObject aElement, java.lang.String anAttribute) throws MarshallException
- Throws:
MarshallException
-
addHelper
public void addHelper(MarshallHelper aHelper)
Add custom helper class.- Parameters:
aHelper
- the custom helper you want to add to the serializer.
-
usePojoAccess
public void usePojoAccess()
The objects that fall back on the general object helper will be serialized by using their fields directly. Without further annotations, the default constructor without arguments will be used in the POJO. If this is not sufficient, the @JSONConstruct and @JSONSerialize annotations can be used as well in the POJO to indicate which constructor has to be used.
-
useJavaBeanAccess
public void useJavaBeanAccess()
The objects that fall back on the general object helper will be serialized by using their JavaBean properties. The JavaBean always needs a default constructor without arguments.
-
-