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 and Description
    --- | ---
    `static interface` | `JSONPojoConvertor.NumberType`
    `static class` | `JSONPojoConvertor.Setter`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Set<String>` | `_excluded`
    `protected boolean` | `_fromJSON`
    `protected Map<String,Method>` | `_getters`
    `protected Class<?>` | `_pojoClass`
    `protected Map<String,JSONPojoConvertor.Setter>` | `_setters`
    `static JSONPojoConvertor.NumberType` | `DOUBLE`
    `static JSONPojoConvertor.NumberType` | `FLOAT`
    `static Object[]` | `GETTER_ARG`
    `static JSONPojoConvertor.NumberType` | `INTEGER`
    `static JSONPojoConvertor.NumberType` | `LONG`
    `static Object[]` | `NULL_ARG`
    `static JSONPojoConvertor.NumberType` | `SHORT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JSONPojoConvertor(Class<?> pojoClass)`
    `JSONPojoConvertor(Class<?> pojoClass, boolean fromJSON)`
    `JSONPojoConvertor(Class<?> pojoClass, Set<String> excluded)`
    `JSONPojoConvertor(Class<?> pojoClass, Set<String> excluded, boolean fromJSON)`
    `JSONPojoConvertor(Class<?> pojoClass, String[] excluded)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addGetter(String name, Method method)`
    `protected void` | `addSetter(String name, Method method)`
    `Object` | `fromJSON(Map object)`
    `protected int` | `getExcludedCount()`
    `static JSONPojoConvertor.NumberType` | `getNumberType(Class<?> clazz)`
    `protected JSONPojoConvertor.Setter` | `getSetter(String name)`
    `protected boolean` | `includeField(String name, Method m)`
    `protected void` | `init()`
    `protected void` | `log(Throwable t)`
    `int` | `setProps(Object obj, Map<?,?> props)`
    `void` | `toJSON(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 Object[] GETTER_ARG

    - #### NULL_ARG

          public static final Object[] NULL_ARG

    - #### _fromJSON

          protected boolean _fromJSON

    - #### _pojoClass

          protected Class<?> _pojoClass

    - #### _getters

          protected Map<String,Method> _getters

    - #### _setters

          protected Map<String,JSONPojoConvertor.Setter> _setters

    - #### _excluded

          protected Set<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(Class<?> pojoClass)

      Parameters:
        `pojoClass` - The class to convert

    - #### JSONPojoConvertor

          public JSONPojoConvertor(Class<?> pojoClass,
                           String[] excluded)

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

    - #### JSONPojoConvertor

          public JSONPojoConvertor(Class<?> pojoClass,
                           Set<String> excluded)

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

    - #### JSONPojoConvertor

          public JSONPojoConvertor(Class<?> pojoClass,
                           Set<String> 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(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(Class<?> clazz)

    - #### init

          protected void init()

    - #### addGetter

          protected void addGetter(String name,
                       Method method)

    - #### addSetter

          protected void addSetter(String name,
                       Method method)

    - #### getSetter

          protected JSONPojoConvertor.Setter getSetter(String name)

    - #### includeField

          protected boolean includeField(String name,
                             Method m)

    - #### getExcludedCount

          protected int getExcludedCount()

    - #### fromJSON

          public Object fromJSON(Map object)

      Specified by:
        `fromJSON` in interface `JSON.Convertor`

    - #### setProps

          public int setProps(Object obj,
                     Map<?,?> props)

    - #### toJSON

          public void toJSON(Object obj,
                    JSON.Output out)

      Specified by:
        `toJSON` in interface `JSON.Convertor`

    - #### log

          protected void log(Throwable t)

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