public class JsonObject extends java.util.LinkedHashMap<java.lang.String,java.lang.Object> implements JsonType, IReadOnlyNamedValues<java.lang.Object>
JSON_ARRAY_END, JSON_ARRAY_START, JSON_ELEMENT_SEPARATOR, JSON_LITERAL_FALSE, JSON_LITERAL_NULL, JSON_LITERAL_TRUE, JSON_OBJECT_END, JSON_OBJECT_START, JSON_PAIR_SEPARATOR, JSON_STRING_DELIMITER, JSON_STRING_ESCAPE
Constructor and Description |
---|
JsonObject() |
JsonObject(int initialCapacity) |
JsonObject(int initialCapacity,
float loadFactor) |
JsonObject(java.util.Map<? extends java.lang.String,? extends java.lang.Object> m) |
Modifier and Type | Method and Description |
---|---|
void |
appendAsJSONString(java.lang.StringBuffer buffer)
The receiver of this method must append its internal state as JSON string
representation to the given buffer.
|
java.math.BigDecimal |
getBigDecimal(java.lang.String name)
Returns the value for the given name as BigDecimal (if it is one).
|
java.lang.Boolean |
getBoolean(java.lang.String name)
Returns the value for the given name as Boolean (if it is one).
|
java.lang.Integer |
getInteger(java.lang.String name)
Returns the value for the given name as Integer (if it is one).
|
JsonArray |
getJsonArray(java.lang.String name)
Returns the value for the given name as JsonArray (if it is one).
|
JsonObject |
getJsonObject(java.lang.String name)
Returns the value for the given name as JsonObject (if it is one).
|
java.lang.Long |
getLong(java.lang.String name)
Returns the value for the given name as Long (if it is one).
|
java.util.Collection<java.lang.String> |
getNames()
Returns all names (maybe empty but never null).
|
java.lang.Number |
getNumber(java.lang.String name)
Returns the value for the given name as Number (if it is one).
|
java.lang.String |
getString(java.lang.String name)
Returns the value for the given name as String (if it is one).
|
protected <T> T |
getTypedElement(java.lang.String name,
java.lang.Class<T> type) |
java.lang.Object |
getValue(java.lang.String name)
Returns the value associated with the given name.
|
<T> T |
getValueOfType(java.lang.String name,
java.lang.Class<T> type)
Returns the value for the given name as type of the given class.
|
boolean |
isArray()
Returns false because this is no JSON array representation (in Java).
|
boolean |
isObject()
Returns true because this is a JSON object representation (in Java).
|
java.lang.Object |
put(java.lang.String key,
java.lang.Object value)
Adds the given element if it is a valid JSON object type.
|
java.lang.String |
toJSON()
The receiver of this method returns its internal state as JSON string
representation.
|
clone, containsKey, entrySet, isEmpty, keySet, putAll, remove, size, values
finalize, getClass, notify, notifyAll, wait, wait, wait
isEmpty
public JsonObject()
public JsonObject(int initialCapacity, float loadFactor)
public JsonObject(int initialCapacity)
public JsonObject(java.util.Map<? extends java.lang.String,? extends java.lang.Object> m)
public java.lang.Object put(java.lang.String key, java.lang.Object value)
Valid types are:
put
in interface java.util.Map<java.lang.String,java.lang.Object>
put
in class java.util.HashMap<java.lang.String,java.lang.Object>
java.lang.IllegalArgumentException
- If the given object is not of a valid JSON type.public JsonObject getJsonObject(java.lang.String name)
name
- The name of the object to look for (must not be null).java.lang.ClassCastException
- If the object associated to the given name is no JsonObject.public JsonArray getJsonArray(java.lang.String name)
name
- The name of the array to look for (must not be null).java.lang.ClassCastException
- If the object associated to the given name is no JsonArray.public java.lang.String getString(java.lang.String name)
name
- The name of the value to look for (must not be null).java.lang.ClassCastException
- If the object associated to the given name is no String.public java.lang.Boolean getBoolean(java.lang.String name)
name
- The name of the value to look for (must not be null).java.lang.ClassCastException
- If the object associated to the given name is no Boolean.public java.lang.Number getNumber(java.lang.String name)
name
- The name of the value to look for (must not be null).java.lang.ClassCastException
- If the object associated to the given name is no Number.public java.lang.Integer getInteger(java.lang.String name)
name
- The name of the value to look for (must not be null).java.lang.ClassCastException
- If the object associated to the given name is no Integer.public java.lang.Long getLong(java.lang.String name)
name
- The name of the value to look for (must not be null).java.lang.ClassCastException
- If the object associated to the given name is no Long.public java.math.BigDecimal getBigDecimal(java.lang.String name)
name
- The name of the value to look for (must not be null).java.lang.ClassCastException
- If the object associated to the given name is no BigDecimal.public <T> T getValueOfType(java.lang.String name, java.lang.Class<T> type)
name
- The name of the value to look for (must not be null).java.lang.IllegalArgumentException
- If the specified type is no valid JSON type.java.lang.ClassCastException
- If the object associated to the given name is not of the specified type.public boolean isObject()
public boolean isArray()
public java.util.Collection<java.lang.String> getNames()
IReadOnlyNamedValues
getNames
in interface IReadOnlyNamedValues<java.lang.Object>
public java.lang.Object getValue(java.lang.String name)
IReadOnlyNamedValues
getValue
in interface IReadOnlyNamedValues<java.lang.Object>
name
- The identifier for which the associated value must be returned (must not be null).public void appendAsJSONString(java.lang.StringBuffer buffer)
IJSONConvertible
appendAsJSONString
in interface IJSONConvertible
buffer
- The buffer to which to append the JSON string (must not be null).public java.lang.String toJSON()
IJSONConvertible
toJSON
in interface IJSONConvertible
protected <T> T getTypedElement(java.lang.String name, java.lang.Class<T> type)