public class JsonObject
extends java.lang.Object
implements java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.Object>>
JsonArray
Constructor and Description |
---|
JsonObject()
Create a new, empty instance.
|
JsonObject(java.util.Map<java.lang.String,java.lang.Object> map)
Create an instance from a Map.
|
Modifier and Type | Method and Description |
---|---|
JsonObject |
clear()
Removes all the entries in this JSON object.
|
boolean |
containsKey(java.lang.String key)
Returns
true if the JSON object contain the specified key. |
boolean |
equals(java.lang.Object o) |
java.util.Set<java.lang.String> |
fieldNames()
Return the set of field names in the JSON objects.
|
byte[] |
getBinary(java.lang.String key)
Returns the binary value with the specified key.
|
byte[] |
getBinary(java.lang.String key,
byte[] def)
Like
getBinary(String) but specifies a default value to return if there is no entry. |
java.lang.Boolean |
getBoolean(java.lang.String key)
Returns the boolean value with the specified key.
|
java.lang.Boolean |
getBoolean(java.lang.String key,
java.lang.Boolean def)
Like
getBoolean(String) but specifies a default value to return if there is no entry. |
java.lang.Double |
getDouble(java.lang.String key)
Returns the double value with the specified key.
|
java.lang.Double |
getDouble(java.lang.String key,
java.lang.Double def)
Like
getDouble(String) but specifies a default value to return if there is no entry. |
java.lang.Float |
getFloat(java.lang.String key)
Returns the float value with the specified key.
|
java.lang.Float |
getFloat(java.lang.String key,
java.lang.Float def)
Like
getFloat(String) but specifies a default value to return if there is no entry. |
java.lang.Integer |
getInteger(java.lang.String key)
returns the integer value with the specified key.
|
java.lang.Integer |
getInteger(java.lang.String key,
java.lang.Integer def)
Like
getInteger(String) but specifies a default value to return if there is no entry. |
JsonArray |
getJsonArray(java.lang.String key)
Returns the
JsonArray value with the specified key |
JsonArray |
getJsonArray(java.lang.String key,
JsonArray def)
Like
getJsonArray(String) but specifies a default value to return if there is no entry. |
JsonObject |
getJsonObject(java.lang.String key)
Returns the
JsonObject value with the specified key. |
JsonObject |
getJsonObject(java.lang.String key,
JsonObject def)
Like
getJsonObject(String) but specifies a default value to return if there is no entry. |
java.lang.Long |
getLong(java.lang.String key)
Returns the long value with the specified key.
|
java.lang.Long |
getLong(java.lang.String key,
java.lang.Long def)
Like
getLong(String) but specifies a default value to return if there is no entry. |
java.lang.String |
getString(java.lang.String key)
Returns the string value with the specified key.
|
java.lang.String |
getString(java.lang.String key,
java.lang.String def)
Like
getString(String) but specifies a default value to return if there is no entry. |
<T> T |
getValue(java.lang.String key)
Returns the value with the specified key, as an object.
|
<T> T |
getValue(java.lang.String key,
T def)
Like
getValue(String) but specifies a default value to return if there is no entry. |
int |
hashCode() |
boolean |
isEmpty()
Returns
true if JSON object is empty. |
java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.Object>> |
iterator()
Returns an iterator of the entries in the JSON object.
|
java.util.Map<java.lang.String,java.lang.Object> |
map()
Returns the underlying
Map as is. |
JsonObject |
mergeIn(JsonObject other)
Merges in another JSON object.
|
JsonObject |
mergeIn(JsonObject other,
int depth)
Merges in another JSON object.
|
JsonObject |
mergeInDeep(JsonObject other)
Merges in another JSON object.
|
JsonObject |
put(java.lang.String key,
java.lang.Boolean value)
Puts a boolean into the JSON object with the specified key.
|
JsonObject |
put(java.lang.String key,
byte[] value)
Puts a
byte[] into the JSON object with the specified key. |
JsonObject |
put(java.lang.String key,
java.lang.CharSequence value)
Puts an
CharSequence into the JSON object with the specified key. |
JsonObject |
put(java.lang.String key,
java.lang.Double value)
Puts a double into the JSON object with the specified key.
|
JsonObject |
put(java.lang.String key,
java.lang.Enum value)
Puts an Enum into the JSON object with the specified key.
|
JsonObject |
put(java.lang.String key,
java.lang.Float value)
Puts a float into the JSON object with the specified key.
|
JsonObject |
put(java.lang.String key,
java.lang.Integer value)
Puts an integer into the JSON object with the specified key.
|
JsonObject |
put(java.lang.String key,
JsonArray value)
Puts a
JsonArray into the JSON object with the specified key. |
JsonObject |
put(java.lang.String key,
JsonObject value)
Puts another JSON object into the JSON object with the specified key.
|
JsonObject |
put(java.lang.String key,
java.lang.Long value)
Puts a long into the JSON object with the specified key.
|
JsonObject |
put(java.lang.String key,
java.lang.Object value)
Puts an object into the JSON object with the specified key.
|
JsonObject |
put(java.lang.String key,
java.lang.String value)
Puts a string into the JSON object with the specified key.
|
JsonObject |
putNull(java.lang.String key)
Puts a
null value into the JSON object with the specified key. |
java.lang.Object |
remove(java.lang.String key)
Removes an entry from this object.
|
int |
size()
Returns the number of entries in the JSON object.
|
java.util.stream.Stream<java.util.Map.Entry<java.lang.String,java.lang.Object>> |
stream()
Returns a stream of the entries in the JSON object.
|
java.lang.String |
toString()
Returns JSON serialized by default
JsonSerializer . |
public JsonObject()
public JsonObject(java.util.Map<java.lang.String,java.lang.Object> map)
public java.lang.String getString(java.lang.String key)
public java.lang.Integer getInteger(java.lang.String key)
public java.lang.Long getLong(java.lang.String key)
public java.lang.Double getDouble(java.lang.String key)
public java.lang.Float getFloat(java.lang.String key)
public java.lang.Boolean getBoolean(java.lang.String key)
public JsonObject getJsonObject(java.lang.String key)
JsonObject
value with the specified key.public JsonArray getJsonArray(java.lang.String key)
JsonArray
value with the specified keypublic byte[] getBinary(java.lang.String key)
JSON itself has no notion of a binary. This extension complies to the RFC-7493. THe byte array is Base64 encoded binary.
public <T> T getValue(java.lang.String key)
public java.lang.String getString(java.lang.String key, java.lang.String def)
getString(String)
but specifies a default value to return if there is no entry.public java.lang.Integer getInteger(java.lang.String key, java.lang.Integer def)
getInteger(String)
but specifies a default value to return if there is no entry.public java.lang.Long getLong(java.lang.String key, java.lang.Long def)
getLong(String)
but specifies a default value to return if there is no entry.public java.lang.Double getDouble(java.lang.String key, java.lang.Double def)
getDouble(String)
but specifies a default value to return if there is no entry.public java.lang.Float getFloat(java.lang.String key, java.lang.Float def)
getFloat(String)
but specifies a default value to return if there is no entry.public java.lang.Boolean getBoolean(java.lang.String key, java.lang.Boolean def)
getBoolean(String)
but specifies a default value to return if there is no entry.public JsonObject getJsonObject(java.lang.String key, JsonObject def)
getJsonObject(String)
but specifies a default value to return if there is no entry.public JsonArray getJsonArray(java.lang.String key, JsonArray def)
getJsonArray(String)
but specifies a default value to return if there is no entry.public byte[] getBinary(java.lang.String key, byte[] def)
getBinary(String)
but specifies a default value to return if there is no entry.public <T> T getValue(java.lang.String key, T def)
getValue(String)
but specifies a default value to return if there is no entry.public boolean containsKey(java.lang.String key)
true
if the JSON object contain the specified key.public java.util.Set<java.lang.String> fieldNames()
public JsonObject put(java.lang.String key, java.lang.Enum value)
JSON has no concept of encoding Enums, so the Enum will be converted to a String using the java.lang.Enum#name
method and the value put as a String.
public JsonObject put(java.lang.String key, java.lang.CharSequence value)
CharSequence
into the JSON object with the specified key.public JsonObject put(java.lang.String key, java.lang.String value)
public JsonObject put(java.lang.String key, java.lang.Integer value)
public JsonObject put(java.lang.String key, java.lang.Long value)
public JsonObject put(java.lang.String key, java.lang.Double value)
public JsonObject put(java.lang.String key, java.lang.Float value)
public JsonObject put(java.lang.String key, java.lang.Boolean value)
public JsonObject putNull(java.lang.String key)
null
value into the JSON object with the specified key.public JsonObject put(java.lang.String key, JsonObject value)
public JsonObject put(java.lang.String key, JsonArray value)
JsonArray
into the JSON object with the specified key.public JsonObject put(java.lang.String key, byte[] value)
byte[]
into the JSON object with the specified key.
Follows JSON extension RFC7493, where binary will first be Base64 encoded before being put as a String.
public JsonObject put(java.lang.String key, java.lang.Object value)
public java.lang.Object remove(java.lang.String key)
public JsonObject mergeIn(JsonObject other)
This is the equivalent of putting all the entries of the other JSON object into this object. This is not a deep merge, entries containing (sub) JSON objects will be replaced entirely.
public JsonObject mergeInDeep(JsonObject other)
public JsonObject mergeIn(JsonObject other, int depth)
public java.util.Map<java.lang.String,java.lang.Object> map()
Map
as is.public java.util.stream.Stream<java.util.Map.Entry<java.lang.String,java.lang.Object>> stream()
public java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.Object>> iterator()
iterator
in interface java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.Object>>
public int size()
public JsonObject clear()
public boolean isEmpty()
true
if JSON object is empty.public java.lang.String toString()
JsonSerializer
.toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
Copyright © 2003-present Jodd Team