Class JSONMarshall
- java.lang.Object
-
- com.sdicons.json.serializer.marshall.JSONMarshall
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringERR_MISSINGATTRstatic java.lang.StringERR_MISSINGATTRVALstatic java.lang.StringERR_MISSINGSTRINGprivate longidCounterprivate static java.lang.StringIDPREFIXprivate HelperRepository<MarshallHelper>repostatic java.lang.StringRNDR_ARRstatic java.lang.StringRNDR_ATTR_CLASSstatic java.lang.StringRNDR_ATTR_IDstatic java.lang.StringRNDR_ATTR_KINDstatic java.lang.StringRNDR_ATTR_REFstatic java.lang.StringRNDR_ATTR_TYPEstatic java.lang.StringRNDR_ATTR_VALUEstatic java.lang.StringRNDR_NULLstatic java.lang.StringRNDR_OBJstatic java.lang.StringRNDR_OBJREFstatic java.lang.StringRNDR_PRIMstatic java.lang.StringRNDR_PRTITYP_BOOLEANstatic java.lang.StringRNDR_PRTITYP_BYTEstatic java.lang.StringRNDR_PRTITYP_CHARstatic java.lang.StringRNDR_PRTITYP_DOUBLEstatic java.lang.StringRNDR_PRTITYP_FLOATstatic java.lang.StringRNDR_PRTITYP_INTstatic java.lang.StringRNDR_PRTITYP_LONGstatic java.lang.StringRNDR_PRTITYP_SHORT
-
Constructor Summary
Constructors Constructor Description JSONMarshall()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHelper(MarshallHelper aHelper)Add custom helper class.private java.lang.StringgenerateId()JSONObjectmarshall(boolean aValue)Convert a boolean primitive to JSON.JSONObjectmarshall(byte aValue)Convert a byte primitive to JSON.JSONObjectmarshall(char aValue)Convert a char primitive to JSON.JSONObjectmarshall(double aValue)Convert a double primitive to JSON.JSONObjectmarshall(float aValue)Convert a float primitive to JSON.JSONObjectmarshall(int aValue)Convert an int primitive to JSON.JSONObjectmarshall(long aValue)Convert a long primitive to JSON.JSONObjectmarshall(short aValue)Convert a short primitive to JSON.JSONObjectmarshall(java.lang.Object aObj)Convert a Java object to JSON.JSONObjectmarshallImpl(java.lang.Object aObj, java.util.HashMap aPool)private JSONObjectmarshallImplArray(java.lang.Object aObj, java.util.HashMap aPool)private JSONObjectmarshallImplObject(java.lang.Object aObj, java.lang.String aObjId, java.lang.Class aObjClass, java.lang.String aObjClassName, java.util.HashMap aPool)private JSONObjectmarshallPrimitive(java.lang.String aType, java.lang.String aValue)static voidrequireStringAttribute(JSONObject aElement, java.lang.String anAttribute)MarshallValueunmarshall(JSONObject aElement)Convert a JSON representation to the Java primitive or reference.java.lang.ObjectunmarshallImpl(JSONObject aElement, java.util.HashMap aObjectPool)private java.lang.ObjectunmarshallImplPrimitive(JSONObject aElement)voiduseJavaBeanAccess()The objects that fall back on the general object helper will be serialized by using their JavaBean properties.voidusePojoAccess()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:MarshallConvert a boolean primitive to JSON.
-
marshall
public JSONObject marshall(byte aValue)
Description copied from interface:MarshallConvert a byte primitive to JSON.
-
marshall
public JSONObject marshall(short aValue)
Description copied from interface:MarshallConvert a short primitive to JSON.
-
marshall
public JSONObject marshall(char aValue)
Description copied from interface:MarshallConvert a char primitive to JSON.
-
marshall
public JSONObject marshall(int aValue)
Description copied from interface:MarshallConvert an int primitive to JSON.
-
marshall
public JSONObject marshall(long aValue)
Description copied from interface:MarshallConvert a long primitive to JSON.
-
marshall
public JSONObject marshall(float aValue)
Description copied from interface:MarshallConvert a float primitive to JSON.
-
marshall
public JSONObject marshall(double aValue)
Description copied from interface:MarshallConvert 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:MarshallConvert a Java object to JSON.- Specified by:
marshallin 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:MarshallConvert a JSON representation to the Java primitive or reference.- Specified by:
unmarshallin 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.
-
-