Package org.json.simple
Class JsonObject
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.
- Since:
- 2.0.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
ConstructorDescriptionInstantiates 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
Modifier and TypeMethodDescriptiongetBigDecimal
(String key) Deprecated.getBigDecimal
(JsonKey key) A convenience method that assumes there is a BigDecimal, Number, or String at the given key.getBigDecimalOrDefault
(String key, BigDecimal defaultValue) Deprecated.2.3.0 in favor ofgetBigDecimalOrDefault(JsonKey)
A convenience method that assumes there is a BigDecimal, Number, or String at the given key.getBoolean
(String key) Deprecated.2.3.0 in favor ofgetBoolean(JsonKey)
getBoolean
(JsonKey key) A convenience method that assumes there is a Boolean or String value at the given key.getBooleanOrDefault
(String key, boolean defaultValue) Deprecated.2.3.0 in favor ofgetBooleanOrDefault(JsonKey)
A convenience method that assumes there is a Boolean or String value at the given key.Deprecated.2.3.0 in favor ofgetByte(JsonKey)
A convenience method that assumes there is a Number or String value at the given key.getByteOrDefault
(String key, byte defaultValue) Deprecated.2.3.0 in favor ofgetByteOrDefault(JsonKey)
getByteOrDefault
(JsonKey key) A convenience method that assumes there is a Number or String value at the given key.<T extends Collection<?>>
TgetCollection
(String key) Deprecated.2.3.0 in favor ofgetCollection(JsonKey)
<T extends Collection<?>>
TgetCollection
(JsonKey key) A convenience method that assumes there is a Collection at the given key.<T extends Collection<?>>
TgetCollectionOrDefault
(String key, T defaultValue) Deprecated.2.3.0 in favor ofgetCollectionOrDefault(JsonKey)
<T extends Collection<?>>
TA convenience method that assumes there is a Collection at the given key.Deprecated.2.3.0 in favor ofgetDouble(JsonKey)
A convenience method that assumes there is a Number or String value at the given key.getDoubleOrDefault
(String key, double defaultValue) Deprecated.2.3.0 in favor ofgetDoubleOrDefault(JsonKey)
A convenience method that assumes there is a Number or String value at the given key.<T extends Enum<T>>
TDeprecated.2.3.0 in favor ofgetEnum(JsonKey)
<T extends Enum<T>>
TDeprecated.2.3.0 Jsoner deprecated automatically serializing enums as Strings.<T extends Enum<T>>
TgetEnumOrDefault
(String key, T defaultValue) Deprecated.2.3.0 in favor ofgetEnumOrDefault(JsonKey)
<T extends Enum<T>>
TgetEnumOrDefault
(JsonKey key) Deprecated.2.3.0 Jsoner deprecated automatically serializing enums as Strings.Deprecated.2.3.0 in favor ofgetFloat(JsonKey)
A convenience method that assumes there is a Number or String value at the given key.getFloatOrDefault
(String key, float defaultValue) Deprecated.2.3.0 in favor ofgetFloatOrDefault(JsonKey)
getFloatOrDefault
(JsonKey key) A convenience method that assumes there is a Number or String value at the given key.getInteger
(String key) Deprecated.2.3.0 in favor ofgetInteger(JsonKey)
getInteger
(JsonKey key) A convenience method that assumes there is a Number or String value at the given key.getIntegerOrDefault
(String key, int defaultValue) Deprecated.2.3.0 in favor ofgetIntegerOrDefault(JsonKey)
A convenience method that assumes there is a Number or String value at the given key.Deprecated.2.3.0 in favor ofgetLong(JsonKey)
A convenience method that assumes there is a Number or String value at the given key.getLongOrDefault
(String key, long defaultValue) Deprecated.2.3.0 in favor ofgetLongOrDefault(JsonKey)
getLongOrDefault
(JsonKey key) A convenience method that assumes there is a Number or String value at the given key.<T extends Map<?,
?>>
TDeprecated.2.3.0 in favor ofgetMap(JsonKey)
<T extends Map<?,
?>>
TA convenience method that assumes there is a Map at the given key.<T extends Map<?,
?>>
TgetMapOrDefault
(String key, T defaultValue) Deprecated.2.3.0 in favor ofgetMapOrDefault(JsonKey)
<T extends Map<?,
?>>
TgetMapOrDefault
(JsonKey key) A convenience method that assumes there is a Map at the given key.Deprecated.2.3.0 in favor ofgetShort(JsonKey)
A convenience method that assumes there is a Number or String value at the given key.getShortOrDefault
(String key, short defaultValue) Deprecated.2.3.0 in favor ofgetShortOrDefault(JsonKey)
getShortOrDefault
(JsonKey key) A convenience method that assumes there is a Number or String value at the given key.Deprecated.2.3.0 in favor ofgetString(JsonKey)
A convenience method that assumes there is a Boolean, Number, or String value at the given key.getStringOrDefault
(String key, String defaultValue) Deprecated.2.3.0 in favor ofgetStringOrDefault(JsonKey)
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.toJson()
Serialize to a JSON formatted string.void
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, newHashMap, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Constructor Details
-
JsonObject
public JsonObject()Instantiates an empty JsonObject. -
JsonObject
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 Details
-
requireKeys
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.- Since:
- 2.3.0 to ensure critical keys are in the JsonObject.
-
getBigDecimal
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getBigDecimal
Deprecated.2.3.0 in favor ofgetBigDecimal(JsonKey)
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 stored at.- Returns:
- the value stored at 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:
-
getBigDecimalOrDefault
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getBigDecimalOrDefault
Deprecated.2.3.0 in favor ofgetBigDecimalOrDefault(JsonKey)
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 stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.- Returns:
- the value stored at the key or the default provided if the key doesn't exist.
- Throws:
ClassCastException
- if there was a value but didn't match the assumed return types.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:
-
getBoolean
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getBoolean
Deprecated.2.3.0 in favor ofgetBoolean(JsonKey)
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 stored at.- Returns:
- the value stored at the key.
- Throws:
ClassCastException
- if the value didn't match the assumed return type.
-
getBooleanOrDefault
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getBooleanOrDefault
Deprecated.2.3.0 in favor ofgetBooleanOrDefault(JsonKey)
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 stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.- Returns:
- the value stored at the key or the default provided if the key doesn't exist.
- Throws:
ClassCastException
- if there was a value but didn't match the assumed return type.
-
getByte
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getByte
Deprecated.2.3.0 in favor ofgetByte(JsonKey)
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 stored at.- Returns:
- the value stored at 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:
-
getByteOrDefault
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getByteOrDefault
Deprecated.2.3.0 in favor ofgetByteOrDefault(JsonKey)
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 stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.- Returns:
- the value stored at the key (which may involve rounding or truncation) or the default provided if the key doesn't exist.
- Throws:
ClassCastException
- if there was a value but 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:
-
getCollection
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getCollection
Deprecated.2.3.0 in favor ofgetCollection(JsonKey)
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 stored at.- Returns:
- the value stored at the key.
- Throws:
ClassCastException
- if the value didn't match the assumed return type.
-
getCollectionOrDefault
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getCollectionOrDefault
Deprecated.2.3.0 in favor ofgetCollectionOrDefault(JsonKey)
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 stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.- Returns:
- the value stored at the key or the default provided if the key doesn't exist.
- Throws:
ClassCastException
- if there was a value but didn't match the assumed return type.
-
getDouble
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getDouble
Deprecated.2.3.0 in favor ofgetDouble(JsonKey)
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 stored at.- Returns:
- the value stored at 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:
-
getDoubleOrDefault
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getDoubleOrDefault
Deprecated.2.3.0 in favor ofgetDoubleOrDefault(JsonKey)
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 stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.- Returns:
- the value stored at the key (which may involve rounding or truncation) or the default provided if the key doesn't exist.
- Throws:
ClassCastException
- if there was a value but 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:
-
getEnum
Deprecated.2.3.0 Jsoner deprecated automatically serializing enums as Strings.A convenience method that assumes there is a String value at the given key representing a fully qualified name in dot notation of an enum.- Type Parameters:
T
- the Enum type the value at the key is expected to belong to.- Parameters:
key
- representing where the value ought to be paired with.- Returns:
- an Enum representing the value paired with the key.
- Throws:
ClassNotFoundException
- if the value was a String but the declaring enum type couldn't be determined with it.ClassCastException
- if the element at the index was not a String or if the fully qualified enum name is of the wrong type.IllegalArgumentException
- if an enum type was determined but it doesn't define an enum with the determined name.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getEnum
Deprecated.2.3.0 in favor ofgetEnum(JsonKey)
A convenience method that assumes there is a String value at the given key representing a fully qualified name in dot notation of an enum.- Type Parameters:
T
- the Enum type the value at the key is expected to belong to.- Parameters:
key
- representing where the value ought to be stored at.- Returns:
- the enum based on the string found at the key, or null if the value paired with the provided key is null.
- Throws:
ClassNotFoundException
- if the value was a String but the declaring enum type couldn't be determined with it.ClassCastException
- if the element at the index was not a String or if the fully qualified enum name is of the wrong type.IllegalArgumentException
- if an enum type was determined but it doesn't define an enum with the determined name.- See Also:
-
getEnumOrDefault
@Deprecated public <T extends Enum<T>> T getEnumOrDefault(JsonKey key) throws ClassNotFoundException Deprecated.2.3.0 Jsoner deprecated automatically serializing enums as Strings.A convenience method that assumes there is a String value at the given key representing a fully qualified name in dot notation of an enum.- Type Parameters:
T
- the Enum type the value at the key is expected to belong to.- Parameters:
key
- representing where the value ought to be paired with.- Returns:
- an Enum representing the value paired with the key or JsonKey#getValue() if the key isn't present.
- Throws:
ClassNotFoundException
- if the value was a String but the declaring enum type couldn't be determined with it.ClassCastException
- if the element at the index was not a String or if the fully qualified enum name is of the wrong type.IllegalArgumentException
- if an enum type was determined but it doesn't define an enum with the determined name.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getEnumOrDefault
@Deprecated public <T extends Enum<T>> T getEnumOrDefault(String key, T defaultValue) throws ClassNotFoundException Deprecated.2.3.0 in favor ofgetEnumOrDefault(JsonKey)
A convenience method that assumes there is a String value at the given key representing a fully qualified name in dot notation of an enum.- Type Parameters:
T
- the Enum type the value at the key is expected to belong to.- Parameters:
key
- representing where the value ought to be stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.- Returns:
- the enum based on the string found at the key, or the defaultValue provided if the key doesn't exist, or null if the value paired with provided key is null.
- Throws:
ClassNotFoundException
- if the value was a String but the declaring enum type couldn't be determined with it.ClassCastException
- if the element at the index was not a String or if the fully qualified enum name is of the wrong type.IllegalArgumentException
- if an enum type was determined but it doesn't define an enum with the determined name.- See Also:
-
getFloat
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getFloat
Deprecated.2.3.0 in favor ofgetFloat(JsonKey)
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 stored at.- Returns:
- the value stored at 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:
-
getFloatOrDefault
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getFloatOrDefault
Deprecated.2.3.0 in favor ofgetFloatOrDefault(JsonKey)
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 stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.- Returns:
- the value stored at the key (which may involve rounding or truncation) or the default provided if the key doesn't exist.
- Throws:
ClassCastException
- if there was a value but 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:
-
getInteger
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getInteger
Deprecated.2.3.0 in favor ofgetInteger(JsonKey)
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 stored at.- Returns:
- the value stored at 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:
-
getIntegerOrDefault
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getIntegerOrDefault
Deprecated.2.3.0 in favor ofgetIntegerOrDefault(JsonKey)
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 stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.- Returns:
- the value stored at the key (which may involve rounding or truncation) or the default provided if the key doesn't exist.
- Throws:
ClassCastException
- if there was a value but 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:
-
getLong
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getLong
Deprecated.2.3.0 in favor ofgetLong(JsonKey)
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 stored at.- Returns:
- the value stored at 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:
-
getLongOrDefault
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getLongOrDefault
Deprecated.2.3.0 in favor ofgetLongOrDefault(JsonKey)
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 stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.- Returns:
- the value stored at the key (which may involve rounding or truncation) or the default provided if the key doesn't exist.
- Throws:
ClassCastException
- if there was a value but 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:
-
getMap
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getMap
Deprecated.2.3.0 in favor ofgetMap(JsonKey)
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 stored at.- Returns:
- the value stored at the key.
- Throws:
ClassCastException
- if the value didn't match the assumed return type.
-
getMapOrDefault
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getMapOrDefault
Deprecated.2.3.0 in favor ofgetMapOrDefault(JsonKey)
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 stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.- Returns:
- the value stored at the key or the default provided if the key doesn't exist.
- Throws:
ClassCastException
- if there was a value but didn't match the assumed return type.
-
getShort
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getShort
Deprecated.2.3.0 in favor ofgetShort(JsonKey)
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 stored at.- Returns:
- the value stored at 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:
-
getShortOrDefault
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getShortOrDefault
Deprecated.2.3.0 in favor ofgetShortOrDefault(JsonKey)
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 stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.- Returns:
- the value stored at the key (which may involve rounding or truncation) or the default provided if the key doesn't exist.
- Throws:
ClassCastException
- if there was a value but 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:
-
getString
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getString
Deprecated.2.3.0 in favor ofgetString(JsonKey)
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 stored at.- Returns:
- the value stored at the key.
- Throws:
ClassCastException
- if the value didn't match the assumed return type.
-
getStringOrDefault
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.- Since:
- 2.3.0 to utilize JsonKey
- See Also:
-
getStringOrDefault
Deprecated.2.3.0 in favor ofgetStringOrDefault(JsonKey)
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 stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.- Returns:
- the value stored at the key or the default provided if the key doesn't exist.
- Throws:
ClassCastException
- if there was a value but didn't match the assumed return type.
-
toJson
Description copied from interface:Jsonable
Serialize to a JSON formatted string. -
toJson
Description copied from interface:Jsonable
Serialize to a JSON formatted stream.- Specified by:
toJson
in interfaceJsonable
- Parameters:
writable
- where the resulting JSON text should be sent.- Throws:
IOException
- when the writable encounters an I/O error.
-
getBigDecimal(JsonKey)