Top Description Inners Fields Constructors Methods
org.mortbay.util.ajax

public Class JSONPojoConvertor

extends Object
implements Convertor
Class Inheritance
All Implemented Interfaces
org.mortbay.util.ajax.JSON.Convertor
Imports
java.lang.reflect.Array, .InvocationTargetException, .Method, .Modifier, java.util.Arrays, .HashMap, .HashSet, .Iterator, .Map, .Set, org.mortbay.log.Log, org.mortbay.util.ajax.JSON.Output

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
Author
dyu

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
public static class

Field Summary

Modifier and TypeField and Description
private static final Map<K, V>
protected Set<E>
protected boolean
protected Map<K, V>
protected Class<T>
protected Map<K, V>
public static final JSONPojoConvertor.NumberType
public static final JSONPojoConvertor.NumberType
public static final Object[]
public static final JSONPojoConvertor.NumberType
public static final JSONPojoConvertor.NumberType
public static final Object[]
public static final JSONPojoConvertor.NumberType

Constructor Summary

AccessConstructor and Description
public
JSONPojoConvertor(Class<T>
The class to convert
pojoClass
)

public
JSONPojoConvertor(Class<T>
The class to convert
pojoClass
,
String[]
The fields to exclude
excluded
)

public
JSONPojoConvertor(Class<T>
The class to convert
pojoClass
,
Set<E>
The fields to exclude
excluded
)

public
JSONPojoConvertor(Class<T>
The class to convert
pojoClass
,
Set<E>
The fields to exclude
excluded
,
boolean
If true, add a class field to the JSON
fromJSON
)

public
JSONPojoConvertor(Class<T>
The class to convert
pojoClass
,
boolean
If true, add a class field to the JSON
fromJSON
)

Method Summary

Modifier and TypeMethod and Description
protected void
addGetter(String name, Method method)

protected void
addSetter(String name, Method method)

public Object
protected int
public static JSONPojoConvertor.NumberType
getNumberType(Class<T> clazz)

protected JSONPojoConvertor.Setter
protected boolean
protected void
init()

protected void
public int
setProps(Object obj, Map<K, V> props)

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

__numberTypesback to summary
private static final Map<K, V> __numberTypes
_excludedback to summary
protected Set<E> _excluded
_fromJSONback to summary
protected boolean _fromJSON
_gettersback to summary
protected Map<K, V> _getters
_pojoClassback to summary
protected Class<T> _pojoClass
_settersback to summary
protected Map<K, V> _setters
DOUBLEback to summary
public static final JSONPojoConvertor.NumberType DOUBLE
FLOATback to summary
public static final JSONPojoConvertor.NumberType FLOAT
GETTER_ARGback to summary
public static final Object[] GETTER_ARG
INTEGERback to summary
public static final JSONPojoConvertor.NumberType INTEGER
LONGback to summary
public static final JSONPojoConvertor.NumberType LONG
NULL_ARGback to summary
public static final Object[] NULL_ARG
SHORTback to summary
public static final JSONPojoConvertor.NumberType SHORT

Constructor Detail

JSONPojoConvertorback to summary
public JSONPojoConvertor(Class<T> pojoClass)
Parameters
pojoClass:Class<T>

The class to convert

JSONPojoConvertorback to summary
public JSONPojoConvertor(Class<T> pojoClass, String[] excluded)
Parameters
pojoClass:Class<T>

The class to convert

excluded:String[]

The fields to exclude

JSONPojoConvertorback to summary
public JSONPojoConvertor(Class<T> pojoClass, Set<E> excluded)
Parameters
pojoClass:Class<T>

The class to convert

excluded:Set<E>

The fields to exclude

JSONPojoConvertorback to summary
public JSONPojoConvertor(Class<T> pojoClass, Set<E> excluded, boolean fromJSON)
Parameters
pojoClass:Class<T>

The class to convert

excluded:Set<E>

The fields to exclude

fromJSON:boolean

If true, add a class field to the JSON

JSONPojoConvertorback to summary
public JSONPojoConvertor(Class<T> pojoClass, boolean fromJSON)
Parameters
pojoClass:Class<T>

The class to convert

fromJSON:boolean

If true, add a class field to the JSON

Method Detail

addGetterback to summary
protected void addGetter(String name, Method method)
addSetterback to summary
protected void addSetter(String name, Method method)
fromJSONback to summary
public Object fromJSON(Map<K, V> object)

Implements org.mortbay.util.ajax.JSON.Convertor.fromJSON.

getExcludedCountback to summary
protected int getExcludedCount()
getNumberTypeback to summary
public static JSONPojoConvertor.NumberType getNumberType(Class<T> clazz)
getSetterback to summary
protected JSONPojoConvertor.Setter getSetter(String name)
includeFieldback to summary
protected boolean includeField(String name, Method m)
initback to summary
protected void init()
logback to summary
protected void log(Throwable t)
setPropsback to summary
public int setProps(Object obj, Map<K, V> props)
toJSONback to summary
public void toJSON(Object obj, JSON.Output out)

Implements org.mortbay.util.ajax.JSON.Convertor.toJSON.

org.mortbay.util.ajax back to summary

public Interface JSONPojoConvertor.NumberType


Method Summary

Modifier and TypeMethod and Description
public Object

Method Detail

getActualValueback to summary
public Object getActualValue(Number number)
org.mortbay.util.ajax back to summary

public Class JSONPojoConvertor.Setter

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
protected Class<T>
protected Method
protected JSONPojoConvertor.NumberType
protected String
protected Class<T>

Constructor Summary

AccessConstructor and Description
public
Setter(String propertyName, Method method)

Method Summary

Modifier and TypeMethod and Description
public Class<T>
public Method
public JSONPojoConvertor.NumberType
public String
public Class<T>
public void
invoke(Object obj, Object value)

protected void
public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_componentTypeback to summary
protected Class<T> _componentType
_methodback to summary
protected Method _method
_numberTypeback to summary
protected JSONPojoConvertor.NumberType _numberType
_propertyNameback to summary
protected String _propertyName
_typeback to summary
protected Class<T> _type

Constructor Detail

Setterback to summary
public Setter(String propertyName, Method method)

Method Detail

getComponentTypeback to summary
public Class<T> getComponentType()
getMethodback to summary
public Method getMethod()
getNumberTypeback to summary
public JSONPojoConvertor.NumberType getNumberType()
getPropertyNameback to summary
public String getPropertyName()
getTypeback to summary
public Class<T> getType()
invokeback to summary
public void invoke(Object obj, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
invokeObjectback to summary
protected void invokeObject(Object obj, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
isPropertyNumberback to summary
public boolean isPropertyNumber()