Class 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 differences with respect to JSONObjectConvertor are:

    • 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
    • Field Detail

      • _fromJSON

        protected boolean _fromJSON
      • _pojoClass

        protected java.lang.Class<?> _pojoClass
      • _getters

        protected java.util.Map<java.lang.String,​java.lang.reflect.Method> _getters
      • _excluded

        protected java.util.Set<java.lang.String> _excluded
    • Constructor Detail

      • JSONPojoConvertor

        public JSONPojoConvertor​(java.lang.Class<?> pojoClass)
        Parameters:
        pojoClass - The class to convert
      • 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
      • 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<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<java.lang.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
    • Method Detail

      • 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)
      • includeField

        protected boolean includeField​(java.lang.String name,
                                       java.lang.reflect.Method m)
      • fromJSON

        public java.lang.Object fromJSON​(java.util.Map<java.lang.String,​java.lang.Object> object)
        Specified by:
        fromJSON in interface JSON.Convertor