Object JSONConverter
-
- All Implemented Interfaces:
public class JSONConverterClass 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.
-
-
Field Summary
Fields Modifier and Type Field Description public final static JSONConverterINSTANCE
-
Method Summary
Modifier and Type Method Description final static UnitloggingEnabled(Boolean enabled)Method to enable logging final static <T extends Any> JSONObjecttoJSON(T obj)Method to convert the given object to an equivalent JSONObject. final static <T extends Any> TfromJSON(JSONObject jsonObject, Class<T> type)Method to convert the given JSONObject to an object equivalent to the given type. final UnitcopyObjects(Object copyFrom, Object copyTo)final static BooleancompareJSON(JSONObject json1, JSONObject json2)-
-
Method Detail
-
loggingEnabled
final static Unit loggingEnabled(Boolean enabled)
Method to enable logging
- Parameters:
enabled-trueif logging is enabled, otherwisefalse
-
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 convertedtype- type of the final object to constructed- Returns:
an equivalent object of the given type filled with the values in the given JSON, otherwise
nullin error scenario.
-
copyObjects
final Unit copyObjects(Object copyFrom, Object copyTo)
-
compareJSON
final static Boolean compareJSON(JSONObject json1, JSONObject json2)
-
-
-
-