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 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 Set<String>_excludedprotected boolean_fromJSONprotected Map<String,Method>_gettersprotected Class<?>_pojoClassprotected Map<String,JSONPojoConvertor.Setter>_settersstatic JSONPojoConvertor.NumberTypeDOUBLEstatic JSONPojoConvertor.NumberTypeFLOATstatic Object[]GETTER_ARGstatic JSONPojoConvertor.NumberTypeINTEGERstatic JSONPojoConvertor.NumberTypeLONGstatic Object[]NULL_ARGstatic JSONPojoConvertor.NumberTypeSHORT
-
Constructor Summary
Constructors Constructor Description JSONPojoConvertor(Class<?> pojoClass)JSONPojoConvertor(Class<?> pojoClass, boolean fromJSON)JSONPojoConvertor(Class<?> pojoClass, String[] excluded)JSONPojoConvertor(Class<?> pojoClass, Set<String> excluded)JSONPojoConvertor(Class<?> pojoClass, Set<String> excluded, boolean fromJSON)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddGetter(String name, Method method)protected voidaddSetter(String name, Method method)ObjectfromJSON(Map object)protected intgetExcludedCount()static JSONPojoConvertor.NumberTypegetNumberType(Class<?> clazz)protected JSONPojoConvertor.SettergetSetter(String name)protected booleanincludeField(String name, Method m)protected voidinit()protected voidlog(Throwable t)intsetProps(Object obj, Map<?,?> props)voidtoJSON(Object obj, JSON.Output out)
-
-
-
Field Detail
-
GETTER_ARG
public static final Object[] GETTER_ARG
-
NULL_ARG
public static final Object[] NULL_ARG
-
_fromJSON
protected boolean _fromJSON
-
_pojoClass
protected Class<?> _pojoClass
-
_setters
protected Map<String,JSONPojoConvertor.Setter> _setters
-
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(Class<?> pojoClass)
- Parameters:
pojoClass- The class to convert
-
JSONPojoConvertor
public JSONPojoConvertor(Class<?> pojoClass, String[] excluded)
- Parameters:
pojoClass- The class to convertexcluded- The fields to exclude
-
JSONPojoConvertor
public JSONPojoConvertor(Class<?> pojoClass, Set<String> excluded)
- Parameters:
pojoClass- The class to convertexcluded- The fields to exclude
-
JSONPojoConvertor
public JSONPojoConvertor(Class<?> pojoClass, Set<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(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(Class<?> clazz)
-
init
protected void init()
-
getSetter
protected JSONPojoConvertor.Setter getSetter(String name)
-
getExcludedCount
protected int getExcludedCount()
-
fromJSON
public Object fromJSON(Map object)
- Specified by:
fromJSONin interfaceJSON.Convertor
-
toJSON
public void toJSON(Object obj, JSON.Output out)
- Specified by:
toJSONin interfaceJSON.Convertor
-
log
protected void log(Throwable t)
-
-