org.json.simple

## Class JsonObject

- java.lang.Object
- - java.util.AbstractMap<K,V>
  - - java.util.HashMap<String,Object>
    - - org.json.simple.JsonObject

- All Implemented Interfaces:
    Serializable, Cloneable, Map<String,Object>, Jsonable

      public class JsonObject
      extends HashMap<String,Object>
      implements Jsonable

  JsonObject is a common non-thread safe data format for string to data mappings. The contents of a JsonObject are only validated as JSON values on serialization. Meaning all values added to a JsonObject must be recognized by the Jsoner for it to be a true 'JsonObject', so it is really a JsonableHashMap that will serialize to a JsonObject if all of its contents are valid JSON.
  See Also:
    `Jsoner`, Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class java.util.AbstractMap

      `AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>`

    - ### Nested classes/interfaces inherited from interface java.util.Map

      `Map.Entry<K,V>`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JsonObject()` Instantiates an empty JsonObject.
    `JsonObject(Map<String,?> map)` Instantiate a new JsonObject by accepting a map's entries, which could lead to de/serialization issues of the resulting JsonObject since the entry values aren't validated as JSON values.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `BigDecimal` | `getBigDecimal(JsonKey key)` A convenience method that assumes there is a BigDecimal, Number, or String at the given key.
    `BigDecimal` | `getBigDecimalOrDefault(JsonKey key)` A convenience method that assumes there is a BigDecimal, Number, or String at the given key.
    `Boolean` | `getBoolean(JsonKey key)` A convenience method that assumes there is a Boolean or String value at the given key.
    `Boolean` | `getBooleanOrDefault(JsonKey key)` A convenience method that assumes there is a Boolean or String value at the given key.
    `Byte` | `getByte(JsonKey key)` A convenience method that assumes there is a Number or String value at the given key.
    `Byte` | `getByteOrDefault(JsonKey key)` A convenience method that assumes there is a Number or String value at the given key.
    `<T extends Collection<?>> T` | `getCollection(JsonKey key)` A convenience method that assumes there is a Collection at the given key.
    `<T extends Collection<?>> T` | `getCollectionOrDefault(JsonKey key)` A convenience method that assumes there is a Collection at the given key.
    `Double` | `getDouble(JsonKey key)` A convenience method that assumes there is a Number or String value at the given key.
    `Double` | `getDoubleOrDefault(JsonKey key)` A convenience method that assumes there is a Number or String value at the given key.
    `Float` | `getFloat(JsonKey key)` A convenience method that assumes there is a Number or String value at the given key.
    `Float` | `getFloatOrDefault(JsonKey key)` A convenience method that assumes there is a Number or String value at the given key.
    `Integer` | `getInteger(JsonKey key)` A convenience method that assumes there is a Number or String value at the given key.
    `Integer` | `getIntegerOrDefault(JsonKey key)` A convenience method that assumes there is a Number or String value at the given key.
    `Long` | `getLong(JsonKey key)` A convenience method that assumes there is a Number or String value at the given key.
    `Long` | `getLongOrDefault(JsonKey key)` A convenience method that assumes there is a Number or String value at the given key.
    `<T extends Map<?,?>> T` | `getMap(JsonKey key)` A convenience method that assumes there is a Map at the given key.
    `<T extends Map<?,?>> T` | `getMapOrDefault(JsonKey key)` A convenience method that assumes there is a Map at the given key.
    `Short` | `getShort(JsonKey key)` A convenience method that assumes there is a Number or String value at the given key.
    `Short` | `getShortOrDefault(JsonKey key)` A convenience method that assumes there is a Number or String value at the given key.
    `String` | `getString(JsonKey key)` A convenience method that assumes there is a Boolean, Number, or String value at the given key.
    `String` | `getStringOrDefault(JsonKey key)` A convenience method that assumes there is a Boolean, Number, or String value at the given key.
    `void` | `requireKeys(JsonKey... keys)` Ensures the given keys are present.
    `String` | `toJson()` Serialize to a JSON formatted string.
    `void` | `toJson(Writer writable)` Serialize to a JSON formatted stream.

    - ### Methods inherited from class java.util.HashMap

      `clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values`

    - ### Methods inherited from class java.util.AbstractMap

      `equals, hashCode, toString`

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.util.Map

      `equals, hashCode`

- - ### Constructor Detail

    - #### JsonObject

          public JsonObject()

      Instantiates an empty JsonObject.

    - #### JsonObject

          public JsonObject(Map<String,?> map)

      Instantiate a new JsonObject by accepting a map's entries, which could lead to de/serialization issues of the resulting JsonObject since the entry values aren't validated as JSON values.
      Parameters:
        `map` - represents the mappings to produce the JsonObject with.

  - ### Method Detail

    - #### getBigDecimal

          public BigDecimal getBigDecimal(JsonKey key)

      A convenience method that assumes there is a BigDecimal, Number, or String at the given key. If a Number is there its Number#toString() is used to construct a new BigDecimal(String). If a String is there it is used to construct a new BigDecimal(String).
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a BigDecimal representing the value paired with the key.
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
        `NumberFormatException` - if a String isn't a valid representation of a BigDecimal or if the Number represents the double or float Infinity or NaN.
      See Also:
        `BigDecimal`, `Object.toString()`, `JsonKey`

    - #### getBigDecimalOrDefault

          public BigDecimal getBigDecimalOrDefault(JsonKey key)

      A convenience method that assumes there is a BigDecimal, Number, or String at the given key. If a Number is there its Number#toString() is used to construct a new BigDecimal(String). If a String is there it is used to construct a new BigDecimal(String).
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a BigDecimal representing the value paired with the key or JsonKey#getValue() if the key isn't present.
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
        `NumberFormatException` - if a String isn't a valid representation of a BigDecimal or if the Number represents the double or float Infinity or NaN.
      See Also:
        `BigDecimal`, `Object.toString()`, `JsonKey`

    - #### getBoolean

          public Boolean getBoolean(JsonKey key)

      A convenience method that assumes there is a Boolean or String value at the given key.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a Boolean representing the value paired with the key.
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
      See Also:
        `JsonKey`

    - #### getBooleanOrDefault

          public Boolean getBooleanOrDefault(JsonKey key)

      A convenience method that assumes there is a Boolean or String value at the given key.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a Boolean representing the value paired with the key or JsonKey#getValue() if the key isn't present.
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
      See Also:
        `JsonKey`

    - #### getByte

          public Byte getByte(JsonKey key)

      A convenience method that assumes there is a Number or String value at the given key.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a Byte representing the value paired with the key (which may involve rounding or truncation).
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
        `NumberFormatException` - if a String isn't a valid representation of a BigDecimal or if the Number represents the double or float Infinity or NaN.
      See Also:
        `Number.byteValue()`, `JsonKey`

    - #### getByteOrDefault

          public Byte getByteOrDefault(JsonKey key)

      A convenience method that assumes there is a Number or String value at the given key.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a Byte representing the value paired with the key or JsonKey#getValue() if the key isn't present (which may involve rounding or truncation).
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
        `NumberFormatException` - if a String isn't a valid representation of a BigDecimal or if the Number represents the double or float Infinity or NaN.
      See Also:
        `Number.byteValue()`, `JsonKey`

    - #### getCollection

          public <T extends Collection<?>> T getCollection(JsonKey key)

      A convenience method that assumes there is a Collection at the given key.
      Type Parameters:
        `T` - the kind of collection to expect at the key. Note unless manually added, collection values will be a JsonArray.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a Collection representing the value paired with the key.
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
      See Also:
        `JsonKey`

    - #### getCollectionOrDefault

          public <T extends Collection<?>> T getCollectionOrDefault(JsonKey key)

      A convenience method that assumes there is a Collection at the given key.
      Type Parameters:
        `T` - the kind of collection to expect at the key. Note unless manually added, collection values will be a JsonArray.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a Collection representing the value paired with the key or JsonKey#getValue() if the key isn't present..
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
      See Also:
        `JsonKey`

    - #### getDouble

          public Double getDouble(JsonKey key)

      A convenience method that assumes there is a Number or String value at the given key.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a Double representing the value paired with the key (which may involve rounding or truncation).
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
        `NumberFormatException` - if a String isn't a valid representation of a BigDecimal or if the Number represents the double or float Infinity or NaN.
      See Also:
        `Number.doubleValue()`, `JsonKey`

    - #### getDoubleOrDefault

          public Double getDoubleOrDefault(JsonKey key)

      A convenience method that assumes there is a Number or String value at the given key.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a Double representing the value paired with the key or JsonKey#getValue() if the key isn't present (which may involve rounding or truncation).
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
        `NumberFormatException` - if a String isn't a valid representation of a BigDecimal or if the Number represents the double or float Infinity or NaN.
      See Also:
        `Number.doubleValue()`, `JsonKey`

    - #### getFloat

          public Float getFloat(JsonKey key)

      A convenience method that assumes there is a Number or String value at the given key.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a Float representing the value paired with the key (which may involve rounding or truncation).
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
        `NumberFormatException` - if a String isn't a valid representation of a BigDecimal or if the Number represents the double or float Infinity or NaN.
      See Also:
        `Number.floatValue()`, `JsonKey`

    - #### getFloatOrDefault

          public Float getFloatOrDefault(JsonKey key)

      A convenience method that assumes there is a Number or String value at the given key.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a Float representing the value paired with the key or JsonKey#getValue() if the key isn't present (which may involve rounding or truncation).
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
        `NumberFormatException` - if a String isn't a valid representation of a BigDecimal or if the Number represents the double or float Infinity or NaN.
      See Also:
        `Number.floatValue()`, `JsonKey`

    - #### getInteger

          public Integer getInteger(JsonKey key)

      A convenience method that assumes there is a Number or String value at the given key.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        an Integer representing the value paired with the key (which may involve rounding or truncation).
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
        `NumberFormatException` - if a String isn't a valid representation of a BigDecimal or if the Number represents the double or float Infinity or NaN.
      See Also:
        `Number.intValue()`, `JsonKey`

    - #### getIntegerOrDefault

          public Integer getIntegerOrDefault(JsonKey key)

      A convenience method that assumes there is a Number or String value at the given key.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        an Integer representing the value paired with the key or JsonKey#getValue() if the key isn't present (which may involve rounding or truncation).
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
        `NumberFormatException` - if a String isn't a valid representation of a BigDecimal or if the Number represents the double or float Infinity or NaN.
      See Also:
        `Number.intValue()`, `JsonKey`

    - #### getLong

          public Long getLong(JsonKey key)

      A convenience method that assumes there is a Number or String value at the given key.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a Long representing the value paired with the key (which may involve rounding or truncation).
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
        `NumberFormatException` - if a String isn't a valid representation of a BigDecimal or if the Number represents the double or float Infinity or NaN.
      See Also:
        `Number.longValue()`, `JsonKey`

    - #### getLongOrDefault

          public Long getLongOrDefault(JsonKey key)

      A convenience method that assumes there is a Number or String value at the given key.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a Long representing the value paired with the key or JsonKey#getValue() if the key isn't present (which may involve rounding or truncation).
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
        `NumberFormatException` - if a String isn't a valid representation of a BigDecimal or if the Number represents the double or float Infinity or NaN.
      See Also:
        `Number.longValue()`, `JsonKey`

    - #### getMap

          public <T extends Map<?,?>> T getMap(JsonKey key)

      A convenience method that assumes there is a Map at the given key.
      Type Parameters:
        `T` - the kind of map to expect at the key. Note unless manually added, Map values will be a JsonObject.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a Map representing the value paired with the key.
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
      See Also:
        `JsonKey`

    - #### getMapOrDefault

          public <T extends Map<?,?>> T getMapOrDefault(JsonKey key)

      A convenience method that assumes there is a Map at the given key.
      Type Parameters:
        `T` - the kind of map to expect at the key. Note unless manually added, Map values will be a JsonObject.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a Map representing the value paired with the key or JsonKey#getValue() if the key isn't present.
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
      See Also:
        `JsonKey`

    - #### getShort

          public Short getShort(JsonKey key)

      A convenience method that assumes there is a Number or String value at the given key.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a Short representing the value paired with the key (which may involve rounding or truncation).
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
        `NumberFormatException` - if a String isn't a valid representation of a BigDecimal or if the Number represents the double or float Infinity or NaN.
      See Also:
        `Number.shortValue()`, `JsonKey`

    - #### getShortOrDefault

          public Short getShortOrDefault(JsonKey key)

      A convenience method that assumes there is a Number or String value at the given key.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a Short representing the value paired with the key or JsonKey#getValue() if the key isn't present (which may involve rounding or truncation).
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
        `NumberFormatException` - if a String isn't a valid representation of a BigDecimal or if the Number represents the double or float Infinity or NaN.
      See Also:
        `Number.shortValue()`, `JsonKey`

    - #### getString

          public String getString(JsonKey key)

      A convenience method that assumes there is a Boolean, Number, or String value at the given key.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a String representing the value paired with the key.
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
      See Also:
        `JsonKey`

    - #### getStringOrDefault

          public String getStringOrDefault(JsonKey key)

      A convenience method that assumes there is a Boolean, Number, or String value at the given key.
      Parameters:
        `key` - representing where the value ought to be paired with.
      Returns:
        a String representing the value paired with the key or JsonKey#getValue() if the key isn't present.
      Throws:
        `ClassCastException` - if the value didn't match the assumed return type.
      See Also:
        `JsonKey`

    - #### requireKeys

          public void requireKeys(JsonKey... keys)

      Ensures the given keys are present.
      Parameters:
        `keys` - represents the keys that must be present.
      Throws:
        `NoSuchElementException` - if any of the given keys are missing.

    - #### toJson

          public String toJson()

      Description copied from interface: `Jsonable`
      Serialize to a JSON formatted string.
      Specified by:
        `toJson` in interface `Jsonable`
      Returns:
        a string, formatted in JSON, that represents the Jsonable.

    - #### toJson

          public void toJson(Writer writable)
                      throws IOException

      Description copied from interface: `Jsonable`
      Serialize to a JSON formatted stream.
      Specified by:
        `toJson` in interface `Jsonable`
      Parameters:
        `writable` - where the resulting JSON text should be sent.
      Throws:
        `IOException` - when the writable encounters an I/O error.