Skip navigation links
com.neurosys.utils

Class JSONMarshaller

    • Field Detail

      • filterNullPropertyFilter

        public static net.sf.json.util.PropertyFilter filterNullPropertyFilter
        Filter out null properties from JSON String TODO: Add Unit test
      • nullFilterConfig

        public static net.sf.json.JsonConfig nullFilterConfig
      • NO_CYCLE_JSON_CONFIG

        public static net.sf.json.JsonConfig NO_CYCLE_JSON_CONFIG
        Prevents Recursive Data Structures
      • DATE_SERVER_DISPLAY_JSON_CONFIG

        public static net.sf.json.JsonConfig DATE_SERVER_DISPLAY_JSON_CONFIG
        Prevents Recursive Data Structures + Handles Date as per DomainUtils.DATE_FORMAT_DISPLAY on Server TODO: Add unit test case
      • defaultNewBeanInstanceStrategy

        public static final net.sf.json.util.NewBeanInstanceStrategy defaultNewBeanInstanceStrategy
    • Method Detail

      • getObjectFromDynaBean

        @Deprecated
        public static final <T,U> T getObjectFromDynaBean(org.apache.commons.beanutils.DynaBean dynaBean,
                                                                      Class<U> claz)
        Deprecated. as it converts the DynaBean to a string and does String manipulations; for objects with complex compositions this fails. Example: Date conversions etc.
        Use JSONObject.toBean(JSONObject.fromObject(dynaBean), entityClass) directly.
        Assumes the MorphDynaBean holds JSON to a single Object
        Type Parameters:
        T -
        U -
        Parameters:
        dynaBean -
        claz -
        Returns:
        Note: All literals containing quotes, =, : , should be encoded
      • getConfig

        public net.sf.json.JsonConfig getConfig(Class rootType)
      • getConfig

        public static net.sf.json.JsonConfig getConfig(Class rootType,
                                                       Class... excludedProperyTypes)
        Gets a bare-bone non-nonsense config that can exclude nulls and certain types of properties
        Parameters:
        rootType -
        excludedProperyTypes -
        Returns:
        TODO: Add unit Test case
      • getConfigForNumberFields

        public static net.sf.json.JsonConfig getConfigForNumberFields(Class rootType,
                                                                      Map<String,Class<Number>> fieldTypesRequired)
        JSON marshalling of Number types can be tricky; and while in JDK 1.8 JSONObject.toBean(JSONObject) is smart enough to introspect and determine the correct type, in JDK 9, there are some issues and we have explicitly ensure the type is the intended type. By default it becomes Integer in JDK 9.
        Parameters:
        rootType - as Class
        fieldTypesRequired - Map of fieldId String to its required Number type.
        Returns:
        JsonConfig
      • getConfig

        public net.sf.json.JsonConfig getConfig()
      • getPropertyFilter

        public net.sf.json.util.PropertyFilter getPropertyFilter()
      • isApplyFilter

        public boolean isApplyFilter()
        Filter un accepted fields out TODO: May make the field redundant or deprecated
      • setApplyFilter

        public void setApplyFilter(boolean applyFilter)
        Filter un accepted fields out TODO: May make the field redundant or deprecated
      • getAcceptedFields

        public List<String> getAcceptedFields()
        Fields to be included/accepted.
        Fields that are neither included nor excluded will be filtered based on filterOnlyIfExcluded
      • setAcceptedFields

        public void setAcceptedFields(List<String> acceptedFields)
        Fields to be included/accepted.
        Fields that are neither included nor excluded will be filtered based on filterOnlyIfExcluded
      • getExcludedFields

        public List<String> getExcludedFields()
        Fields to be excluded.
        Fields that are neither included nor excluded will be filtered based on filterOnlyIfExcluded
      • setExcludedFields

        public void setExcludedFields(List<String> excludedFields)
        Fields to be excluded.
        Fields that are neither included nor excluded will be filtered based on filterOnlyIfExcluded
      • isFilterNulls

        public boolean isFilterNulls()
        If false will NOT filter out nulls
        Default value:
        false
      • setFilterNulls

        public void setFilterNulls(boolean filterNulls)
        If false will NOT filter out nulls
        Default value:
        false
      • getAcceptedClasses

        public Map<Class,JSONMarshaller> getAcceptedClasses()
        Map of Class to JSONMarshaller to nest another types filter configs. Value can be null in which case it means the Class is an acepted type without specific filtering details.
      • setAcceptedClasses

        public void setAcceptedClasses(Map<Class,JSONMarshaller> acceptedClasses)
        Map of Class to JSONMarshaller to nest another types filter configs. Value can be null in which case it means the Class is an acepted type without specific filtering details.
      • isFilterOnlyIfExcluded

        public boolean isFilterOnlyIfExcluded()
        If true will only filter whats in the excludedFields. If false will only include whats in the acceptedFields
        Default value:
        true
      • setFilterOnlyIfExcluded

        public void setFilterOnlyIfExcluded(boolean filterOnlyIfExcluded)
        If true will only filter whats in the excludedFields. If false will only include whats in the acceptedFields
        Default value:
        true
      • classObjectToJson

        public static String classObjectToJson(Object obj,
                                               net.sf.json.JsonConfig config)
        Ensures while marshalling the Class details are also there in the JSON result
        Parameters:
        Object - obj
        Returns:
        String TODO: Add unit test case
      • isJSONArray

        public static boolean isJSONArray(String json)
      • isJSONObject

        public static boolean isJSONObject(String json)
      • isJSON

        public static boolean isJSON(String json)
      • decorateClassOverride

        public void decorateClassOverride(Map<Class,Function<net.sf.json.JSONObject,Object>> classTojsonObjectConsumer)
        Override the class impl assumed by JsonConfig with our own
        Parameters:
        jc - as JsonConfig
        classTojsonObjectConsumer - as Map of Class that is coming/assumed by default in JSON and we wish to override
      • convertToAttributes

        public static void convertToAttributes(Map attributes,
                                               Function<net.sf.ezmorph.bean.MorphDynaBean,EntityAttribute> morpher)
        Since Map attributes are hard to convert to a specific class type. Since for Map values for each dynamic value one has to Map value name --> Class. Using JsonConfig.setClassMap(Map); if its not already of desirec type. By default MorphDynaBean is put.

Copyright © 2018. All rights reserved.