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

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

        protected void log​(java.lang.Throwable t)