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 |
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<?>> |
getCollection(JsonKey key)
A convenience method that assumes there is a Collection at the given key.
|
<T extends Collection<?>> |
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<?,?>> |
getMap(JsonKey key)
A convenience method that assumes there is a Map at the given key.
|
<T extends Map<?,?>> |
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.
|
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 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
public void requireKeys(JsonKey... keys)
keys
- represents the keys that must be present.NoSuchElementException
- if any of the given keys are missing.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 © 2018. All rights reserved.