Interface JSONClass

All Superinterfaces:
JSONObject, com.github.tadukoo.util.pojo.MappedPojo
All Known Subinterfaces:
OrderedJSONClass
All Known Implementing Classes:
AbstractJSONClass, AbstractOrderedJSONClass

public interface JSONClass extends JSONObject, com.github.tadukoo.util.pojo.MappedPojo
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 Details

    • convertToJSON

      default String convertToJSON(JSONConverter converter)
      Converts this JSON object into an actual JSON string
      Specified by:
      convertToJSON in interface JSONObject
      Parameters:
      converter - A JSON converter used for converting sub-objects if needed
      Returns:
      A JSON string representing this object
    • buildJSON

      default String buildJSON(Collection<String> keys, JSONConverter converter)
      Builds the JSON string using the given Collection of keys and a JSONConverter. This method is used in case we need to get the keys in a different way in sub-classes (and convertToJSON(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 ordered
      converter - The JSONConverter to use for converting
      Returns:
      The JSON string representation of this JSONClass
    • getJSONArrayItem

      Grabs the item with the given key as a List, using the fact that it's a JSONArray.
      Type Parameters:
      T - The class of items in the list/array
      Parameters:
      key - The key for the item to be grabbed
      clazz - 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 class
      InvocationTargetException - If something goes wrong in casting the objects
      InstantiationException - If something goes wrong in instantiating the objects
      IllegalAccessException - If we illegally access a constructor while casting
    • getJSONArrayItemNoThrow

      default <T> JSONArray<T> getJSONArrayItemNoThrow(String key, Class<T> clazz)
      Helper method to cast an item being stored in this JSON class as a proper JSONArray easily. The class specified for the JSONArray can be a JSONClass, but if so, it must have a constructor that accepts a JSONClass.

      This version does not throw any exceptions and will not log any errors, just return null if something goes wrong
      Type Parameters:
      T - The class of the items in the JSONArray
      Parameters:
      key - The key of the item to grab
      clazz - The class to be used in the JSONArray
      Returns:
      The item as a proper JSONArray instance, or null
    • 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 proper JSONArray easily. The class specified for the JSONArray can be a JSONClass, but if so, it must have a constructor that accepts a JSONClass.

      This version does not throw any exceptions and will log any errors to the given EasyLogger, then return null if something goes wrong
      Type Parameters:
      T - The class of the items in the JSONArray
      Parameters:
      logger - The EasyLogger to log any errors to
      key - The key of the item to grab
      clazz - The class to be used in the JSONArray
      Returns:
      The item as a proper JSONArray instance, or null