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, valuesequals, hashCode, toStringpublic 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(),
JsonKeypublic 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(),
JsonKeypublic 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.JsonKeypublic 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.JsonKeypublic 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(),
JsonKeypublic 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(),
JsonKeypublic <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.JsonKeypublic <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.JsonKeypublic 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(),
JsonKeypublic 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(),
JsonKeypublic 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(),
JsonKeypublic 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(),
JsonKeypublic 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(),
JsonKeypublic 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(),
JsonKeypublic 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(),
JsonKeypublic 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(),
JsonKeypublic <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.JsonKeypublic <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.JsonKeypublic 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(),
JsonKeypublic 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(),
JsonKeypublic 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.JsonKeypublic 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.JsonKeypublic void requireKeys(JsonKey... keys)
keys - represents the keys that must be present.NoSuchElementException - if any of the given keys are missing.public String toJson()
Jsonablepublic void toJson(Writer writable) throws IOException
JsonabletoJson in interface Jsonablewritable - where the resulting JSON text should be sent.IOException - when the writable encounters an I/O error.