public class JsonObject extends HashMap<String,Object> implements Jsonable
Jsoner
,
Serialized FormAbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
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.
|
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 |
getBigDecimal(String key)
Deprecated.
2.3.0 in favor of
getBigDecimal(JsonKey) |
BigDecimal |
getBigDecimalOrDefault(JsonKey key)
A convenience method that assumes there is a BigDecimal, Number, or String at the given key.
|
BigDecimal |
getBigDecimalOrDefault(String key,
BigDecimal defaultValue)
Deprecated.
2.3.0 in favor of
getBigDecimalOrDefault(JsonKey) |
Boolean |
getBoolean(JsonKey key)
A convenience method that assumes there is a Boolean or String value at the given key.
|
Boolean |
getBoolean(String key)
Deprecated.
2.3.0 in favor of
getBoolean(JsonKey) |
Boolean |
getBooleanOrDefault(JsonKey key)
A convenience method that assumes there is a Boolean or String value at the given key.
|
Boolean |
getBooleanOrDefault(String key,
boolean defaultValue)
Deprecated.
2.3.0 in favor of
getBooleanOrDefault(JsonKey) |
Byte |
getByte(JsonKey key)
A convenience method that assumes there is a Number or String value at the given key.
|
Byte |
getByte(String key)
Deprecated.
2.3.0 in favor of
getByte(JsonKey) |
Byte |
getByteOrDefault(JsonKey key)
A convenience method that assumes there is a Number or String value at the given key.
|
Byte |
getByteOrDefault(String key,
byte defaultValue)
Deprecated.
2.3.0 in favor of
getByteOrDefault(JsonKey) |
<T extends Collection<?>> |
getCollection(JsonKey key)
A convenience method that assumes there is a Collection at the given key.
|
<T extends Collection<?>> |
getCollection(String key)
Deprecated.
2.3.0 in favor of
getCollection(JsonKey) |
<T extends Collection<?>> |
getCollectionOrDefault(JsonKey key)
A convenience method that assumes there is a Collection at the given key.
|
<T extends Collection<?>> |
getCollectionOrDefault(String key,
T defaultValue)
Deprecated.
2.3.0 in favor of
getCollectionOrDefault(JsonKey) |
Double |
getDouble(JsonKey key)
A convenience method that assumes there is a Number or String value at the given key.
|
Double |
getDouble(String key)
Deprecated.
2.3.0 in favor of
getDouble(JsonKey) |
Double |
getDoubleOrDefault(JsonKey key)
A convenience method that assumes there is a Number or String value at the given key.
|
Double |
getDoubleOrDefault(String key,
double defaultValue)
Deprecated.
2.3.0 in favor of
getDoubleOrDefault(JsonKey) |
<T extends Enum<T>> |
getEnum(JsonKey key)
Deprecated.
2.3.0 Jsoner deprecated automatically serializing enums as Strings.
|
<T extends Enum<T>> |
getEnum(String key)
Deprecated.
2.3.0 in favor of
getEnum(JsonKey) |
<T extends Enum<T>> |
getEnumOrDefault(JsonKey key)
Deprecated.
2.3.0 Jsoner deprecated automatically serializing enums as Strings.
|
<T extends Enum<T>> |
getEnumOrDefault(String key,
T defaultValue)
Deprecated.
2.3.0 in favor of
getEnumOrDefault(JsonKey) |
Float |
getFloat(JsonKey key)
A convenience method that assumes there is a Number or String value at the given key.
|
Float |
getFloat(String key)
Deprecated.
2.3.0 in favor of
getFloat(JsonKey) |
Float |
getFloatOrDefault(JsonKey key)
A convenience method that assumes there is a Number or String value at the given key.
|
Float |
getFloatOrDefault(String key,
float defaultValue)
Deprecated.
2.3.0 in favor of
getFloatOrDefault(JsonKey) |
Integer |
getInteger(JsonKey key)
A convenience method that assumes there is a Number or String value at the given key.
|
Integer |
getInteger(String key)
Deprecated.
2.3.0 in favor of
getInteger(JsonKey) |
Integer |
getIntegerOrDefault(JsonKey key)
A convenience method that assumes there is a Number or String value at the given key.
|
Integer |
getIntegerOrDefault(String key,
int defaultValue)
Deprecated.
2.3.0 in favor of
getIntegerOrDefault(JsonKey) |
Long |
getLong(JsonKey key)
A convenience method that assumes there is a Number or String value at the given key.
|
Long |
getLong(String key)
Deprecated.
2.3.0 in favor of
getLong(JsonKey) |
Long |
getLongOrDefault(JsonKey key)
A convenience method that assumes there is a Number or String value at the given key.
|
Long |
getLongOrDefault(String key,
long defaultValue)
Deprecated.
2.3.0 in favor of
getLongOrDefault(JsonKey) |
<T extends Map<?,?>> |
getMap(JsonKey key)
A convenience method that assumes there is a Map at the given key.
|
<T extends Map<?,?>> |
getMap(String key)
Deprecated.
2.3.0 in favor of
getMap(JsonKey) |
<T extends Map<?,?>> |
getMapOrDefault(JsonKey key)
A convenience method that assumes there is a Map at the given key.
|
<T extends Map<?,?>> |
getMapOrDefault(String key,
T defaultValue)
Deprecated.
2.3.0 in favor of
getMapOrDefault(JsonKey) |
Short |
getShort(JsonKey key)
A convenience method that assumes there is a Number or String value at the given key.
|
Short |
getShort(String key)
Deprecated.
2.3.0 in favor of
getShort(JsonKey) |
Short |
getShortOrDefault(JsonKey key)
A convenience method that assumes there is a Number or String value at the given key.
|
Short |
getShortOrDefault(String key,
short defaultValue)
Deprecated.
2.3.0 in favor of
getShortOrDefault(JsonKey) |
String |
getString(JsonKey key)
A convenience method that assumes there is a Boolean, Number, or String value at the given key.
|
String |
getString(String key)
Deprecated.
2.3.0 in favor of
getString(JsonKey) |
String |
getStringOrDefault(JsonKey key)
A convenience method that assumes there is a Boolean, Number, or String value at the given key.
|
String |
getStringOrDefault(String key,
String defaultValue)
Deprecated.
2.3.0 in favor of
getStringOrDefault(JsonKey) |
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.
|
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
equals, hashCode, toString
public JsonObject()
public JsonObject(Map<String,?> map)
map
- represents the mappings to produce the JsonObject with.public void requireKeys(JsonKey... keys)
keys
- represents the keys that must be present.NoSuchElementException
- if any of the given keys are missing.public BigDecimal getBigDecimal(JsonKey key)
key
- representing where the value ought to be paired with.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.BigDecimal
,
Object.toString()
,
JsonKey
@Deprecated public BigDecimal getBigDecimal(String key)
getBigDecimal(JsonKey)
key
- representing where the value ought to be stored at.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.BigDecimal
,
Object.toString()
public BigDecimal getBigDecimalOrDefault(JsonKey key)
key
- representing where the value ought to be paired with.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.BigDecimal
,
Object.toString()
,
JsonKey
@Deprecated public BigDecimal getBigDecimalOrDefault(String key, BigDecimal defaultValue)
getBigDecimalOrDefault(JsonKey)
key
- representing where the value ought to be stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.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.BigDecimal
,
Object.toString()
public Boolean getBoolean(JsonKey key)
key
- representing where the value ought to be paired with.ClassCastException
- if the value didn't match the assumed return type.JsonKey
@Deprecated public Boolean getBoolean(String key)
getBoolean(JsonKey)
key
- representing where the value ought to be stored at.ClassCastException
- if the value didn't match the assumed return type.public Boolean getBooleanOrDefault(JsonKey key)
key
- representing where the value ought to be paired with.ClassCastException
- if the value didn't match the assumed return type.JsonKey
@Deprecated public Boolean getBooleanOrDefault(String key, boolean defaultValue)
getBooleanOrDefault(JsonKey)
key
- representing where the value ought to be stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.ClassCastException
- if there was a value but didn't match the assumed return type.public Byte getByte(JsonKey key)
key
- representing where the value ought to be paired with.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.Number.byteValue()
,
JsonKey
@Deprecated public Byte getByte(String key)
getByte(JsonKey)
key
- representing where the value ought to be stored at.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.Number.byteValue()
public Byte getByteOrDefault(JsonKey key)
key
- representing where the value ought to be paired with.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.Number.byteValue()
,
JsonKey
@Deprecated public Byte getByteOrDefault(String key, byte defaultValue)
getByteOrDefault(JsonKey)
key
- representing where the value ought to be stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.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.Number.byteValue()
public <T extends Collection<?>> T getCollection(JsonKey key)
T
- the kind of collection to expect at the key. Note unless manually added, collection values will be a
JsonArray.key
- representing where the value ought to be paired with.ClassCastException
- if the value didn't match the assumed return type.JsonKey
@Deprecated public <T extends Collection<?>> T getCollection(String key)
getCollection(JsonKey)
T
- the kind of collection to expect at the key. Note unless manually added, collection values will be a
JsonArray.key
- representing where the value ought to be stored at.ClassCastException
- if the value didn't match the assumed return type.public <T extends Collection<?>> T getCollectionOrDefault(JsonKey key)
T
- the kind of collection to expect at the key. Note unless manually added, collection values will be a
JsonArray.key
- representing where the value ought to be paired with.ClassCastException
- if the value didn't match the assumed return type.JsonKey
@Deprecated public <T extends Collection<?>> T getCollectionOrDefault(String key, T defaultValue)
getCollectionOrDefault(JsonKey)
T
- the kind of collection to expect at the key. Note unless manually added, collection values will be a
JsonArray.key
- representing where the value ought to be stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.ClassCastException
- if there was a value but didn't match the assumed return type.public Double getDouble(JsonKey key)
key
- representing where the value ought to be paired with.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.Number.doubleValue()
,
JsonKey
@Deprecated public Double getDouble(String key)
getDouble(JsonKey)
key
- representing where the value ought to be stored at.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.Number.doubleValue()
public Double getDoubleOrDefault(JsonKey key)
key
- representing where the value ought to be paired with.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.Number.doubleValue()
,
JsonKey
@Deprecated public Double getDoubleOrDefault(String key, double defaultValue)
getDoubleOrDefault(JsonKey)
key
- representing where the value ought to be stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.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.Number.doubleValue()
@Deprecated public <T extends Enum<T>> T getEnum(JsonKey key) throws ClassNotFoundException
T
- the Enum type the value at the key is expected to belong to.key
- representing where the value ought to be paired with.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.Enum.valueOf(Class, String)
,
JsonKey
@Deprecated public <T extends Enum<T>> T getEnum(String key) throws ClassNotFoundException
getEnum(JsonKey)
T
- the Enum type the value at the key is expected to belong to.key
- representing where the value ought to be stored at.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.Enum.valueOf(Class, String)
@Deprecated public <T extends Enum<T>> T getEnumOrDefault(JsonKey key) throws ClassNotFoundException
T
- the Enum type the value at the key is expected to belong to.key
- representing where the value ought to be paired with.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.Enum.valueOf(Class, String)
,
JsonKey
@Deprecated public <T extends Enum<T>> T getEnumOrDefault(String key, T defaultValue) throws ClassNotFoundException
getEnumOrDefault(JsonKey)
T
- the Enum type the value at the key is expected to belong to.key
- representing where the value ought to be stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.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.Enum.valueOf(Class, String)
public Float getFloat(JsonKey key)
key
- representing where the value ought to be paired with.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.Number.floatValue()
,
JsonKey
@Deprecated public Float getFloat(String key)
getFloat(JsonKey)
key
- representing where the value ought to be stored at.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.Number.floatValue()
public Float getFloatOrDefault(JsonKey key)
key
- representing where the value ought to be paired with.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.Number.floatValue()
,
JsonKey
@Deprecated public Float getFloatOrDefault(String key, float defaultValue)
getFloatOrDefault(JsonKey)
key
- representing where the value ought to be stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.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.Number.floatValue()
public Integer getInteger(JsonKey key)
key
- representing where the value ought to be paired with.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.Number.intValue()
,
JsonKey
@Deprecated public Integer getInteger(String key)
getInteger(JsonKey)
key
- representing where the value ought to be stored at.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.Number.intValue()
public Integer getIntegerOrDefault(JsonKey key)
key
- representing where the value ought to be paired with.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.Number.intValue()
,
JsonKey
@Deprecated public Integer getIntegerOrDefault(String key, int defaultValue)
getIntegerOrDefault(JsonKey)
key
- representing where the value ought to be stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.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.Number.intValue()
public Long getLong(JsonKey key)
key
- representing where the value ought to be paired with.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.Number.longValue()
,
JsonKey
@Deprecated public Long getLong(String key)
getLong(JsonKey)
key
- representing where the value ought to be stored at.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.Number.longValue()
public Long getLongOrDefault(JsonKey key)
key
- representing where the value ought to be paired with.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.Number.longValue()
,
JsonKey
@Deprecated public Long getLongOrDefault(String key, long defaultValue)
getLongOrDefault(JsonKey)
key
- representing where the value ought to be stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.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.Number.longValue()
public <T extends Map<?,?>> T getMap(JsonKey key)
T
- the kind of map to expect at the key. Note unless manually added, Map values will be a JsonObject.key
- representing where the value ought to be paired with.ClassCastException
- if the value didn't match the assumed return type.JsonKey
@Deprecated public <T extends Map<?,?>> T getMap(String key)
getMap(JsonKey)
T
- the kind of map to expect at the key. Note unless manually added, Map values will be a JsonObject.key
- representing where the value ought to be stored at.ClassCastException
- if the value didn't match the assumed return type.public <T extends Map<?,?>> T getMapOrDefault(JsonKey key)
T
- the kind of map to expect at the key. Note unless manually added, Map values will be a JsonObject.key
- representing where the value ought to be paired with.ClassCastException
- if the value didn't match the assumed return type.JsonKey
@Deprecated public <T extends Map<?,?>> T getMapOrDefault(String key, T defaultValue)
getMapOrDefault(JsonKey)
T
- the kind of map to expect at the key. Note unless manually added, Map values will be a JsonObject.key
- representing where the value ought to be stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.ClassCastException
- if there was a value but didn't match the assumed return type.public Short getShort(JsonKey key)
key
- representing where the value ought to be paired with.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.Number.shortValue()
,
JsonKey
@Deprecated public Short getShort(String key)
getShort(JsonKey)
key
- representing where the value ought to be stored at.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.Number.shortValue()
public Short getShortOrDefault(JsonKey key)
key
- representing where the value ought to be paired with.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.Number.shortValue()
,
JsonKey
@Deprecated public Short getShortOrDefault(String key, short defaultValue)
getShortOrDefault(JsonKey)
key
- representing where the value ought to be stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.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.Number.shortValue()
public String getString(JsonKey key)
key
- representing where the value ought to be paired with.ClassCastException
- if the value didn't match the assumed return type.JsonKey
@Deprecated public String getString(String key)
getString(JsonKey)
key
- representing where the value ought to be stored at.ClassCastException
- if the value didn't match the assumed return type.public String getStringOrDefault(JsonKey key)
key
- representing where the value ought to be paired with.ClassCastException
- if the value didn't match the assumed return type.JsonKey
@Deprecated public String getStringOrDefault(String key, String defaultValue)
getStringOrDefault(JsonKey)
key
- representing where the value ought to be stored at.defaultValue
- representing what is returned when the key isn't in the JsonObject.ClassCastException
- if there was a value but didn't match the assumed return type.public String toJson()
Jsonable
public void toJson(Writer writable) throws IOException
Jsonable
toJson
in interface Jsonable
writable
- where the resulting JSON text should be sent.IOException
- when the writable encounters an I/O error.Copyright © 2017. All rights reserved.