Interface Json

All Superinterfaces:
JsonGenerator, Serializable

public interface Json extends JsonGenerator, Serializable
Defines the required methods callable on a JSON object, to get type-safe properties, check existence, and convert to various degrees of string (pretty print etc).
  • Method Summary

    Modifier and Type
    Method
    Description
    Calls asPrettyString with the deepest depth and a default indent width of 4.
    asPrettyString(int depth)
    Creates a string representation of the current object with a given depth of object expansion
    asPrettyString(int depth, int indentWidth)
    Creates a string representation of the current object with a given depth of object expansion And a custom level of indentation
    Calls as string with the deepest depth
    asString(int depth)
    Creates a string representation of the current object with a given depth of object expansion
    boolean
    Used to check if a given key is present in this JSON object (Object in this sentence refers to any JSON data-type).
    boolean
    Used to check if every provided key appears in the current JSON object.
    Convert the contents of consecutive Strings into the JSON representation of them.
    createFromString(String jsonFragment)
    Convert the contents of a String into the JSON representation.
    boolean
    equals(Object other)
    Replica of the .equals on a class, but used to enforce that implementors will override.
    Used to get the JSON datatype of the current object regardless of the underlying datatype it represents.
    The same as getAny, but at a path in the JSON given by key.
    Used to get the array value of this JSON object, if it was itself, an array.
    The same as getArray, but at a path in the JSON given by key.
    boolean
    Used to get the boolean value of this JSON object, if it was itself, a boolean.
    boolean
    The same as getBoolean, but at a path in the JSON given by key.
    Used to figure out which Datatype this JSON object represents from the JSON standard.
    The same as getDataType, but at a path in the JSON given by key.
    double
    Used to get the double value of this JSON object, if it was itself, a double.
    double
    The same as getDouble, but at a path in the JSON given by key.
    Used to get the Object value of this JSON object, if it was itself, an Object.
    The same as getJSONObject, but at a path in the JSON given by key.
    Used to get a list of all possible keys available at the current depth/level of json.
    The same as getKeys, but at a path in the JSON given by key.
    long
    Used to get the long value of this JSON object, if it was itself, a long.
    long
    The same as getLong, but at a path in the JSON given by key.
    Used to get the string value of this JSON object, if it was itself, a string.
    The same as getString, but at a path in the JSON given by key.
    Used to get the underlying value of each JSON datatype in a non-typesafe manner.
    The same as getValue, but at a path in the JSON given by key.
    Used to get a list of all values of the current JSON object.
    The same as getValues, but at a path in the JSON given by key.
    int
    Used to enforce the implementation of a Hashcode on Implementers
    Calls asPrettyString with the shallowest depth and a default indent width of 4.
    Calls as string with the shallowest depth

    Methods inherited from interface com.clumd.projects.javajson.api.JsonGenerator

    convertToJSON
  • Method Details

    • createFromString

      Json createFromString(String jsonFragment) throws JsonParseException
      Convert the contents of a String into the JSON representation.
      Parameters:
      jsonFragment - A string to be converted.
      Returns:
      A JSON object representing the contents of the string.
      Throws:
      JsonParseException - Thrown if the string was not valid JSON syntax.
    • createFromMultilineString

      Json createFromMultilineString(List<String> jsonFragment) throws JsonParseException
      Convert the contents of consecutive Strings into the JSON representation of them.
      Parameters:
      jsonFragment - A list of strings (usually originating from each line of a .json file), for a single JSON.
      Returns:
      A JSON object representing the contents of the list of strings.
      Throws:
      JsonParseException - Thrown if any of the input contains invalid JSON syntax.
    • contains

      boolean contains(String key)
      Used to check if a given key is present in this JSON object (Object in this sentence refers to any JSON data-type).
      Parameters:
      key - The path within the JSON to check for existence.
      Returns:
      True if a value was found at the given key, false if not.
    • containsAllKeys

      boolean containsAllKeys(Collection<String> keys)
      Used to check if every provided key appears in the current JSON object.
      Parameters:
      keys - The collection of JSON key paths to check for existence.
      Returns:
      True if every key in the collection was found, False if one or more keys was missing from the JSON.
    • getValue

      Object getValue()
      Used to get the underlying value of each JSON datatype in a non-typesafe manner.
      Returns:
      The Java data value this JSON object wraps.
    • getDataType

      JSType getDataType()
      Used to figure out which Datatype this JSON object represents from the JSON standard.
      Returns:
      The datatype of this JSON object.
    • getKeys

      List<String> getKeys()
      Used to get a list of all possible keys available at the current depth/level of json.

      I.e. if you have an object where each child has its own properties, you will only get a list of the children, NOT of the children's children.

      Returns:
      The list of all possible keys of this JSON object.
    • getValues

      List<Json> getValues()
      Used to get a list of all values of the current JSON object.
      Returns:
      The list of all values of this JSON object.
    • getArray

      List<Json> getArray() throws KeyDifferentTypeException
      Used to get the array value of this JSON object, if it was itself, an array.
      Returns:
      The Array value of the current JSON object.
      Throws:
      KeyDifferentTypeException - Thrown if this JSON object represents something other than an array.
    • getBoolean

      boolean getBoolean() throws KeyDifferentTypeException
      Used to get the boolean value of this JSON object, if it was itself, a boolean.
      Returns:
      The boolean value of the current JSON object.
      Throws:
      KeyDifferentTypeException - Thrown if this JSON object represents something other than a boolean.
    • getDouble

      double getDouble() throws KeyDifferentTypeException
      Used to get the double value of this JSON object, if it was itself, a double.
      Returns:
      The double value of the current JSON object.
      Throws:
      KeyDifferentTypeException - Thrown if this JSON object represents something other than a double.
    • getLong

      long getLong() throws KeyDifferentTypeException
      Used to get the long value of this JSON object, if it was itself, a long.
      Returns:
      The long value of the current JSON object.
      Throws:
      KeyDifferentTypeException - Thrown if this JSON object represents something other than a long.
    • getString

      String getString() throws KeyDifferentTypeException
      Used to get the string value of this JSON object, if it was itself, a string.

      You should NOT use this method to get the String representation of this object, see toString style methods.

      Returns:
      The string value of the current JSON object.
      Throws:
      KeyDifferentTypeException - Thrown if this JSON object represents something other than a string.
    • getJSONObject

      Json getJSONObject() throws KeyDifferentTypeException
      Used to get the Object value of this JSON object, if it was itself, an Object.
      Returns:
      The Object value of the current JSON object.
      Throws:
      KeyDifferentTypeException - Thrown if this JSON object represents something other than an Object.
    • getAny

      Json getAny()
      Used to get the JSON datatype of the current object regardless of the underlying datatype it represents.
      Returns:
      The current object as a JSON regardless of the underlying datatype it represents.
    • getValueAt

      Object getValueAt(String key) throws JsonKeyException
      The same as getValue, but at a path in the JSON given by key.
      Parameters:
      key - The key / path from the current JSON object to the target you want.
      Returns:
      Any value (non-type safe) present at the given key.
      Throws:
      JsonKeyException - Thrown if they key is malformed, or there was not a property at the provided key.
    • getJSONObjectAt

      Json getJSONObjectAt(String key) throws JsonKeyException
      The same as getJSONObject, but at a path in the JSON given by key.
      Parameters:
      key - The key / path from the current JSON object to the target you want.
      Returns:
      Any JSON OBJECT type present at the given key.
      Throws:
      JsonKeyException - Thrown if they key is malformed, there was not a property at the provided key, or the datatype of the value at key, was not OBJECT.
    • getDataTypeOf

      JSType getDataTypeOf(String key) throws JsonKeyException
      The same as getDataType, but at a path in the JSON given by key.
      Parameters:
      key - The key / path from the current JSON object to the target you want.
      Returns:
      The JSON datatype present at the given key.
      Throws:
      JsonKeyException - Thrown if they key is malformed, or there was not a property at the provided key.
    • getKeysOf

      List<String> getKeysOf(String key) throws JsonKeyException
      The same as getKeys, but at a path in the JSON given by key.
      Parameters:
      key - The key / path from the current JSON object to the target you want.
      Returns:
      A list of all possible keys present from the point the given key.
      Throws:
      JsonKeyException - Thrown if they key is malformed, or there was not a property at the provided key.
    • getValuesOf

      List<Json> getValuesOf(String key) throws JsonKeyException
      The same as getValues, but at a path in the JSON given by key.
      Parameters:
      key - The key / path from the current JSON object to the target you want.
      Returns:
      All values present from the given key.
      Throws:
      JsonKeyException - Thrown if they key is malformed, or there was not a property at the provided key.
    • getArrayAt

      List<Json> getArrayAt(String key) throws JsonKeyException
      The same as getArray, but at a path in the JSON given by key.
      Parameters:
      key - The key / path from the current JSON object to the target you want.
      Returns:
      Any JSON ARRAY type present at the given key.
      Throws:
      JsonKeyException - Thrown if they key is malformed, there was not a property at the provided key, or the datatype of the value at key, was not ARRAY.
    • getBooleanAt

      boolean getBooleanAt(String key) throws JsonKeyException
      The same as getBoolean, but at a path in the JSON given by key.
      Parameters:
      key - The key / path from the current JSON object to the target you want.
      Returns:
      Any JSON BOOLEAN type present at the given key.
      Throws:
      JsonKeyException - Thrown if they key is malformed, there was not a property at the provided key, or the datatype of the value at key, was not BOOLEAN.
    • getDoubleAt

      double getDoubleAt(String key) throws JsonKeyException
      The same as getDouble, but at a path in the JSON given by key.
      Parameters:
      key - The key / path from the current JSON object to the target you want.
      Returns:
      Any JSON DOUBLE type present at the given key.
      Throws:
      JsonKeyException - Thrown if they key is malformed, there was not a property at the provided key, or the datatype of the value at key, was not DOUBLE.
    • getLongAt

      long getLongAt(String key) throws JsonKeyException
      The same as getLong, but at a path in the JSON given by key.
      Parameters:
      key - The key / path from the current JSON object to the target you want.
      Returns:
      Any JSON LONG type present at the given key.
      Throws:
      JsonKeyException - Thrown if they key is malformed, there was not a property at the provided key, or the datatype of the value at key, was not LONG.
    • getStringAt

      String getStringAt(String key) throws JsonKeyException
      The same as getString, but at a path in the JSON given by key.

      You should NOT use this method to get the String representation of this object, see toString style methods.

      Parameters:
      key - The key / path from the current JSON object to the target you want.
      Returns:
      Any JSON STRING type present at the given key.
      Throws:
      JsonKeyException - Thrown if they key is malformed, there was not a property at the provided key, or the datatype of the value at key, was not STRING.
    • getAnyAt

      Json getAnyAt(String key) throws JsonKeyException
      The same as getAny, but at a path in the JSON given by key.
      Parameters:
      key - The key / path from the current JSON object to the target you want.
      Returns:
      The Java wrapping JSON data present at the given key.
      Throws:
      JsonKeyException - Thrown if they key is malformed, there was not a property at the provided key.
    • toString

      String toString()
      Calls as string with the shallowest depth
      Overrides:
      toString in class Object
      Returns:
      The highest level view of the current object
    • toPrettyString

      String toPrettyString()
      Calls asPrettyString with the shallowest depth and a default indent width of 4.
      Returns:
      The highest level view of the current object, with new lines and object indentation
    • asString

      String asString()
      Calls as string with the deepest depth
      Returns:
      The most detailed view of the current object
    • asString

      String asString(int depth)
      Creates a string representation of the current object with a given depth of object expansion
      Parameters:
      depth - The depth of objects to show in the output
      Returns:
      The string representation of this object
    • asPrettyString

      String asPrettyString()
      Calls asPrettyString with the deepest depth and a default indent width of 4.
      Returns:
      The most detailed view of the current object, with new lines and object indentation
    • asPrettyString

      String asPrettyString(int depth)
      Creates a string representation of the current object with a given depth of object expansion
      Parameters:
      depth - The depth of objects to show in the output
      Returns:
      The string representation of this object, with new lines and object indentation
    • asPrettyString

      String asPrettyString(int depth, int indentWidth)
      Creates a string representation of the current object with a given depth of object expansion And a custom level of indentation
      Parameters:
      depth - The depth of objects to show in the output
      indentWidth - How wide each subsequent indentation should be on child properties.
      Returns:
      The string representation of this object, with new lines and object indentation
    • equals

      boolean equals(Object other)
      Replica of the .equals on a class, but used to enforce that implementors will override.
      Overrides:
      equals in class Object
      Parameters:
      other - Another instance of a JsonObject.
      Returns:
      The equality state of the two objects in question.
    • hashCode

      int hashCode()
      Used to enforce the implementation of a Hashcode on Implementers
      Overrides:
      hashCode in class Object
      Returns:
      The Hashcode of this JsonObject