Object JSONConverter

  • All Implemented Interfaces:

    
    public class JSONConverter
    
                        

    Class to convert the given object to an equivalent JSONObject and vice versa. This class will consider the member variables in the conversion process in infinite cycle. Any variable whose type doesn't fall under the types supported type by JSONObject will be ignored.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Constructor Detail

    • Method Detail

      • loggingEnabled

         final static Unit loggingEnabled(Boolean enabled)

        Method to enable logging

        Parameters:
        enabled - true if logging is enabled, otherwise false
      • toJSON

         final static <T extends Any> JSONObject toJSON(T obj)

        Method to convert the given object to an equivalent JSONObject. This method will also consider the member variables in the conversion process in infinite cycle. Any variable whose type doesn't fall under the types supported type by JSONObject will be ignored.

        Parameters:
        obj - The object to be converted
        Returns:

        the equivalent JSONObject, otherwise null

      • fromJSON

         final static <T extends Any> T fromJSON(JSONObject jsonObject, Class<T> type)

        Method to convert the given JSONObject to an object equivalent to the given type. Ensure the given object(s) taken into conversion has a default zero argument constructor.

        Parameters:
        jsonObject - JSON equivalent of the object to converted
        type - type of the final object to constructed
        Returns:

        an equivalent object of the given type filled with the values in the given JSON, otherwise null in error scenario.