Interface JSONObject

All Superinterfaces:
Comparable<JSONNode>, JSONMapNode, JSONNode, Serializable

public interface JSONObject
extends JSONMapNode
A JSON Object consisting of a collection of key-value pairs
Author:
Jim Earley (xml.jim@gmail.com)
  • Method Details

    • put

      void put​(String key, Number n)
      Adds or replaces a number value
      Parameters:
      key - the key
      n - the number
    • put

      void put​(String key, String s)
      Adds or replaces a String value
      Parameters:
      key - the key
      s - the string value
    • put

      void put​(String key, boolean b)
      Adds or replaces a boolean value
      Parameters:
      key - the key
      b - the boolean value
    • put

      default void put​(String key, JSONNode node)
      Set a JSONNode (either a JSONObject or JSONArray)
      Parameters:
      key - the key
      node - the JSONNode
    • put

      void put​(String key, JSONArray a)
      Adds or replaces a JSONArray value
      Parameters:
      key - the key
      a - the JSONArray
    • put

      void put​(String key, JSONObject o)
      Adds or replaces a JSONObject value
      Parameters:
      key - the key
      o - the JSONObject
    • putNull

      void putNull​(String key)
      Put a null value associated with a key
      Parameters:
      key - the key
    • getJSONObject

      JSONObject getJSONObject​(String key)
      Return a JSONObject with the associated key
      Parameters:
      key - the key
      Returns:
      a JSONObject
    • getJSONArray

      JSONArray getJSONArray​(String key)
      Return a JSONArray
      Parameters:
      key - the key
      Returns:
      a JSONArray
    • getNumber

      Number getNumber​(String key)
      Return a Number. Value can be cast to the appropriate underlying type
      Parameters:
      key - the key
      Returns:
      a Number
    • getLong

      long getLong​(String key)
      Return a long value
      Parameters:
      key - the key
      Returns:
      long value
    • getInt

      int getInt​(String key)
      Return an integer
      Parameters:
      key - the key
      Returns:
      the integer value
    • getBoolean

      boolean getBoolean​(String key)
      Return a boolean
      Parameters:
      key - the key
      Returns:
      the boolean value
    • getValueType

      JSONValueType getValueType​(String key)
      Returns the JSON value type
      Parameters:
      key - the key
      Returns:
      the value type
    • getString

      String getString​(String key)
      Return a String
      Parameters:
      key - the key
      Returns:
      the String value
    • getValue

      default <T> T getValue​(String key)
      Return a casted value
      Type Parameters:
      T - The cast type
      Parameters:
      key - the key
      Returns:
      the casted value
    • merge

      default void merge​(JSONObject secondary, ArrayConflict arrayConflict, ObjectConflict objectConflict)
      Merge another JSONObject into this instance.

      HERE THERE BE DRAGONS: Once the merge happens, the original Node value is replaced. Know your data

      Parameters:
      secondary - the other JSONObject instance to merge
      arrayConflict - the Array Conflict Strategy to use
      objectConflict - the Object Conflict Strategy to use
    • mergeToCopy

      default JSONObject mergeToCopy​(JSONObject secondary, ArrayConflict arrayConflict, ObjectConflict objectConflict)
      Merge the current JSONObject instance with another and return the merged instance. The original instance is left in its original state.
      Parameters:
      secondary - the other JSONObject instance to merge
      arrayConflict - the Array Conflict Strategy to use
      objectConflict - the Object Conflict Strategy to use
      Returns: