Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.mortbay.util.ajax
Class JSONPojoConvertor

    java.lang.Object
      org.mortbay.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

Author:
  dyu

Nested Class Summary
`static interface` | `JSONPojoConvertor.NumberType`
`static class` | `JSONPojoConvertor.Setter`

Field Summary
`protected java.util.Set` | `_excluded`
`protected boolean` | `_fromJSON`
`protected java.util.Map` | `_getters`
`protected java.lang.Class` | `_pojoClass`
`protected java.util.Map` | `_setters`
`static JSONPojoConvertor.NumberType` | `DOUBLE`
`static JSONPojoConvertor.NumberType` | `FLOAT`
`static java.lang.Object[]` | `GETTER_ARG`
`static JSONPojoConvertor.NumberType` | `INTEGER`
`static JSONPojoConvertor.NumberType` | `LONG`
`static java.lang.Object[]` | `NULL_ARG`
`static JSONPojoConvertor.NumberType` | `SHORT`

Constructor Summary
`JSONPojoConvertor(java.lang.Class pojoClass)`
`JSONPojoConvertor(java.lang.Class pojoClass, boolean fromJSON)`
`JSONPojoConvertor(java.lang.Class pojoClass, java.util.Set excluded)`
`JSONPojoConvertor(java.lang.Class pojoClass, java.util.Set excluded, boolean fromJSON)`
`JSONPojoConvertor(java.lang.Class pojoClass, java.lang.String[] excluded)`

Method Summary
`protected void` | `addGetter(java.lang.String name, java.lang.reflect.Method method)`
`protected void` | `addSetter(java.lang.String name, java.lang.reflect.Method method)`
`java.lang.Object` | `fromJSON(java.util.Map object)`
`protected int` | `getExcludedCount()`
`static JSONPojoConvertor.NumberType` | `getNumberType(java.lang.Class clazz)`
`protected JSONPojoConvertor.Setter` | `getSetter(java.lang.String name)`
`protected boolean` | `includeField(java.lang.String name, java.lang.reflect.Method m)`
`protected void` | `init()`
`protected void` | `log(java.lang.Throwable t)`
`int` | `setProps(java.lang.Object obj, java.util.Map props)`
`void` | `toJSON(java.lang.Object obj, JSON.Output out)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

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 _getters

### _setters

    protected java.util.Map _setters

### _excluded

    protected java.util.Set _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 convert
  `excluded` - The fields to exclude

### JSONPojoConvertor

    public JSONPojoConvertor(java.lang.Class pojoClass,
                             java.util.Set excluded)

Parameters:
  `pojoClass` - The class to convert
  `excluded` - The fields to exclude

### JSONPojoConvertor

    public JSONPojoConvertor(java.lang.Class pojoClass,
                             java.util.Set excluded,
                             boolean fromJSON)

Parameters:
  `pojoClass` - The class to convert
  `excluded` - The fields to exclude
  `fromJSON` - If true, add a class field to the JSON

### JSONPojoConvertor

    public JSONPojoConvertor(java.lang.Class pojoClass,
                             boolean fromJSON)

Parameters:
  `pojoClass` - The class to convert
  `fromJSON` - 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:
    `fromJSON` in interface `JSON.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:
    `toJSON` in interface `JSON.Convertor`

### log

    protected void log(java.lang.Throwable t)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 1995-2010 Mort Bay Consulting. All Rights Reserved.