Package com.ubs.backend.annotations.json
Class JSONParser
java.lang.Object
com.ubs.backend.annotations.json.JSONParser
Class which is used to parse JsonSerializableObject into a JSONObject
- passed Object has to be of a Class which is annotated with JsonSerializableObject
- it should contain at least one Field annotated with JsonElement or JsonFunction or JsonMethod
- See Also:
JsonSerializableObject,JsonField,JsonMethod
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map<String,ElementHandler>The Map of all Handlers for Objects -
Constructor Summary
ConstructorsConstructorDescriptionno-args constructorJSONParser(Map<String,ElementHandler> handlers)Constructor to set the list of handlers to your own -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHandler(ElementHandler... handlers)Adds one or multiple Handlers to a listprivate voidcheckIfSerializable(Object object)Checks if an object is Serializableprivate StringgetJsonString(Object object)private voidlistToJSON(Object[] values, Class<?> clazz, ParserResponseType response)listToJSON(List<?> list, Class<?> clazz, ParserResponseType response)objectToJSON(Object object)
-
Field Details
-
handlers
The Map of all Handlers for Objects. - The Key is the type of the Handler which it will handle - The Value is an Instance of the handler
-
-
Constructor Details
-
JSONParser
public JSONParser()no-args constructor -
JSONParser
Constructor to set the list of handlers to your own- Parameters:
handlers- the list of handlers
-
-
Method Details
-
addHandler
Adds one or multiple Handlers to a list- Parameters:
handlers- the list of handlers
-
checkIfSerializable
Checks if an object is Serializable- Parameters:
object- the object to check- Throws:
JSONParser.JsonSerializationException- if the Object cannot be serialized
-
getJsonString
private String getJsonString(Object object) throws JSONParser.JsonSerializationException, IllegalAccessException, ElementTypeException, InvocationTargetException -
handleKeyObjectPair
private void handleKeyObjectPair(Map<String,String> jsonElements, String key, Object o, String type) throws ElementTypeException, JSONParser.JsonSerializationException -
objectToJSON
-
listToJSON
public String listToJSON(List<?> list, Class<?> clazz, ParserResponseType response) throws JSONParser.JsonSerializationException -
listToJSON
public String listToJSON(Object[] values, Class<?> clazz, ParserResponseType response) throws JSONParser.JsonSerializationException
-