Package com.github.tadukoo.parsing.json
Interface JSONClass
- All Superinterfaces:
JSONObject
,com.github.tadukoo.util.pojo.MappedPojo
- All Known Subinterfaces:
OrderedJSONClass
- All Known Implementing Classes:
AbstractJSONClass
,AbstractOrderedJSONClass
JSON Class represents a collection of named values in JSON. It's represented using
MappedPojo
.- Version:
- Alpha v.0.1
- Author:
- Logan Ferree (Tadukoo)
-
Method Summary
Modifier and TypeMethodDescriptiondefault String
buildJSON
(Collection<String> keys, JSONConverter converter) Builds the JSON string using the given Collection of keys and aJSONConverter
.default String
convertToJSON
(JSONConverter converter) Converts this JSON object into an actual JSON stringdefault <T> JSONArray<T>
getJSONArrayItem
(String key, Class<T> clazz) default <T> JSONArray<T>
getJSONArrayItemNoThrow
(com.github.tadukoo.util.logger.EasyLogger logger, String key, Class<T> clazz) Helper method to cast an item being stored in this JSON class as a properJSONArray
easily.default <T> JSONArray<T>
getJSONArrayItemNoThrow
(String key, Class<T> clazz) Helper method to cast an item being stored in this JSON class as a properJSONArray
easily.Methods inherited from interface com.github.tadukoo.util.pojo.MappedPojo
clear, getItem, getKeys, getListItem, getListItemNoThrow, getListItemNoThrow, getMap, getPojoItem, getPojoItemNoThrow, getPojoItemNoThrow, hasItem, hasKey, isEmpty, removeItem, setItem
-
Method Details
-
convertToJSON
Converts this JSON object into an actual JSON string- Specified by:
convertToJSON
in interfaceJSONObject
- Parameters:
converter
- A JSON converter used for converting sub-objects if needed- Returns:
- A JSON string representing this object
-
buildJSON
Builds the JSON string using the given Collection of keys and aJSONConverter
. This method is used in case we need to get the keys in a different way in sub-classes (andconvertToJSON(JSONConverter)
can be overridden and used to pass the keys differently).- Parameters:
keys
- The Collection of keys to be used - may be ordered or not orderedconverter
- TheJSONConverter
to use for converting- Returns:
- The JSON string representation of this JSONClass
-
getJSONArrayItem
default <T> JSONArray<T> getJSONArrayItem(String key, Class<T> clazz) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException - Type Parameters:
T
- The class of items in the list/array- Parameters:
key
- The key for the item to be grabbedclazz
- The class of items in the list/array- Returns:
- A List containing the items from the JSON Array
- Throws:
NoSuchMethodException
- If we can't find the constructor for the given classInvocationTargetException
- If something goes wrong in casting the objectsInstantiationException
- If something goes wrong in instantiating the objectsIllegalAccessException
- If we illegally access a constructor while casting
-
getJSONArrayItemNoThrow
Helper method to cast an item being stored in this JSON class as a properJSONArray
easily. The class specified for theJSONArray
can be aJSONClass
, but if so, it must have a constructor that accepts aJSONClass
.
This version does not throw any exceptions and will not log any errors, just return null if something goes wrong -
getJSONArrayItemNoThrow
default <T> JSONArray<T> getJSONArrayItemNoThrow(com.github.tadukoo.util.logger.EasyLogger logger, String key, Class<T> clazz) Helper method to cast an item being stored in this JSON class as a properJSONArray
easily. The class specified for theJSONArray
can be aJSONClass
, but if so, it must have a constructor that accepts aJSONClass
.
This version does not throw any exceptions and will log any errors to the givenEasyLogger
, then return null if something goes wrong
-