Package org.eclipse.jetty.util.ajax
Class JSONPojoConvertor
- java.lang.Object
-
- org.eclipse.jetty.util.ajax.JSONPojoConvertor
-
- All Implemented Interfaces:
JSON.Convertor
public class JSONPojoConvertor extends java.lang.Object implements JSON.Convertor
Converts POJOs to JSON and vice versa. The key difference: - returns the actual object from Convertor.fromJSON (JSONObjectConverter returns a Map) - the getters/setters are resolved at initialization (JSONObjectConverter resolves it at runtime) - correctly sets the number fields
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceJSONPojoConvertor.NumberTypestatic classJSONPojoConvertor.Setter
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Set<java.lang.String>_excludedprotected boolean_fromJSONprotected java.util.Map<java.lang.String,java.lang.reflect.Method>_gettersprotected java.lang.Class<?>_pojoClassprotected java.util.Map<java.lang.String,JSONPojoConvertor.Setter>_settersstatic JSONPojoConvertor.NumberTypeDOUBLEstatic JSONPojoConvertor.NumberTypeFLOATstatic java.lang.Object[]GETTER_ARGstatic JSONPojoConvertor.NumberTypeINTEGERstatic JSONPojoConvertor.NumberTypeLONGstatic java.lang.Object[]NULL_ARGstatic JSONPojoConvertor.NumberTypeSHORT
-
Constructor Summary
Constructors Constructor Description JSONPojoConvertor(java.lang.Class<?> pojoClass)JSONPojoConvertor(java.lang.Class<?> pojoClass, boolean fromJSON)JSONPojoConvertor(java.lang.Class<?> pojoClass, java.lang.String[] excluded)JSONPojoConvertor(java.lang.Class<?> pojoClass, java.util.Set<java.lang.String> excluded)JSONPojoConvertor(java.lang.Class<?> pojoClass, java.util.Set<java.lang.String> excluded, boolean fromJSON)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddGetter(java.lang.String name, java.lang.reflect.Method method)protected voidaddSetter(java.lang.String name, java.lang.reflect.Method method)java.lang.ObjectfromJSON(java.util.Map object)protected intgetExcludedCount()static JSONPojoConvertor.NumberTypegetNumberType(java.lang.Class<?> clazz)protected JSONPojoConvertor.SettergetSetter(java.lang.String name)protected booleanincludeField(java.lang.String name, java.lang.reflect.Method m)protected voidinit()protected voidlog(java.lang.Throwable t)intsetProps(java.lang.Object obj, java.util.Map<?,?> props)voidtoJSON(java.lang.Object obj, JSON.Output out)
-
-
-
Field Detail
-
GETTER_ARG
public static final java.lang.Object[] GETTER_ARG
-
NULL_ARG
public static final java.lang.Object[] NULL_ARG
-
_fromJSON
protected boolean _fromJSON
-
_pojoClass
protected java.lang.Class<?> _pojoClass
-
_getters
protected java.util.Map<java.lang.String,java.lang.reflect.Method> _getters
-
_setters
protected java.util.Map<java.lang.String,JSONPojoConvertor.Setter> _setters
-
_excluded
protected java.util.Set<java.lang.String> _excluded
-
SHORT
public static final JSONPojoConvertor.NumberType SHORT
-
INTEGER
public static final JSONPojoConvertor.NumberType INTEGER
-
FLOAT
public static final JSONPojoConvertor.NumberType FLOAT
-
LONG
public static final JSONPojoConvertor.NumberType LONG
-
DOUBLE
public static final JSONPojoConvertor.NumberType DOUBLE
-
-
Constructor Detail
-
JSONPojoConvertor
public JSONPojoConvertor(java.lang.Class<?> pojoClass)
- Parameters:
pojoClass- The class to convert
-
JSONPojoConvertor
public JSONPojoConvertor(java.lang.Class<?> pojoClass, java.lang.String[] excluded)- Parameters:
pojoClass- The class to convertexcluded- The fields to exclude
-
JSONPojoConvertor
public JSONPojoConvertor(java.lang.Class<?> pojoClass, java.util.Set<java.lang.String> excluded)- Parameters:
pojoClass- The class to convertexcluded- The fields to exclude
-
JSONPojoConvertor
public JSONPojoConvertor(java.lang.Class<?> pojoClass, java.util.Set<java.lang.String> excluded, boolean fromJSON)- Parameters:
pojoClass- The class to convertexcluded- The fields to excludefromJSON- If true, add a class field to the JSON
-
JSONPojoConvertor
public JSONPojoConvertor(java.lang.Class<?> pojoClass, boolean fromJSON)- Parameters:
pojoClass- The class to convertfromJSON- If true, add a class field to the JSON
-
-
Method Detail
-
getNumberType
public static JSONPojoConvertor.NumberType getNumberType(java.lang.Class<?> clazz)
-
init
protected void init()
-
addGetter
protected void addGetter(java.lang.String name, java.lang.reflect.Method method)
-
addSetter
protected void addSetter(java.lang.String name, java.lang.reflect.Method method)
-
getSetter
protected JSONPojoConvertor.Setter getSetter(java.lang.String name)
-
includeField
protected boolean includeField(java.lang.String name, java.lang.reflect.Method m)
-
getExcludedCount
protected int getExcludedCount()
-
fromJSON
public java.lang.Object fromJSON(java.util.Map object)
- Specified by:
fromJSONin interfaceJSON.Convertor
-
setProps
public int setProps(java.lang.Object obj, java.util.Map<?,?> props)
-
toJSON
public void toJSON(java.lang.Object obj, JSON.Output out)- Specified by:
toJSONin interfaceJSON.Convertor
-
log
protected void log(java.lang.Throwable t)
-
-