public class JsonObject extends JsonValue
Represents a JSON object that can be stored and loaded from Couchbase Server.
If boxed return values are unboxed, the calling code needs to make sure to handle potential NullPointerException
s.
The JsonObject
is backed by a Map
and is intended to work similar to it API wise, but to only allow to store such objects which can be represented by JSON.
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(java.lang.String name)
Checks if the
JsonObject contains the field name. |
boolean |
containsValue(java.lang.Object value)
Checks if the
JsonObject contains the value. |
static JsonObject |
create()
Creates a empty
JsonObject . |
static JsonObject |
empty()
Creates a empty
JsonObject . |
boolean |
equals(java.lang.Object o) |
java.lang.Object |
get(java.lang.String name)
Retrieves the (potential null) content and not casting its type.
|
JsonArray |
getArray(java.lang.String name)
Retrieves the value from the field name and casts it to
JsonArray . |
java.lang.Boolean |
getBoolean(java.lang.String name)
Retrieves the value from the field name and casts it to
Boolean . |
java.lang.Double |
getDouble(java.lang.String name)
Retrieves the value from the field name and casts it to
Double . |
java.lang.Integer |
getInt(java.lang.String name)
Retrieves the value from the field name and casts it to
Integer . |
java.lang.Long |
getLong(java.lang.String name)
Retrieves the value from the field name and casts it to
Long . |
java.util.Set<java.lang.String> |
getNames()
Returns a set of field names on the
JsonObject . |
JsonObject |
getObject(java.lang.String name)
Retrieves the value from the field name and casts it to
JsonObject . |
java.lang.String |
getString(java.lang.String name)
Retrieves the value from the field name and casts it to
String . |
int |
hashCode() |
boolean |
isEmpty()
Returns true if the
JsonObject is empty, false otherwise. |
JsonObject |
put(java.lang.String name,
boolean value)
Stores a
Boolean value identified by the field name. |
JsonObject |
put(java.lang.String name,
double value)
Stores a
Double value identified by the field name. |
JsonObject |
put(java.lang.String name,
int value)
Stores a
Integer value identified by the field name. |
JsonObject |
put(java.lang.String name,
JsonArray value)
Stores a
JsonArray value identified by the field name. |
JsonObject |
put(java.lang.String name,
JsonObject value)
Stores a
JsonObject value identified by the field name. |
JsonObject |
put(java.lang.String name,
long value)
Stores a
Long value identified by the field name. |
JsonObject |
put(java.lang.String name,
java.lang.Object value)
Stores a
Object value identified by the field name. |
JsonObject |
put(java.lang.String name,
java.lang.String value)
Stores a
String value identified by the field name. |
int |
size()
The size of the
JsonObject . |
java.util.Map<java.lang.String,java.lang.Object> |
toMap()
Creates a copy of the underlying
Map and returns it. |
java.lang.String |
toString()
Converts the
JsonObject into its JSON string representation. |
public static JsonObject empty()
Creates a empty JsonObject
.
JsonObject
.public static JsonObject create()
Creates a empty JsonObject
.
JsonObject
.public JsonObject put(java.lang.String name, java.lang.Object value)
Stores a Object
value identified by the field name.
Note that the value is checked and a IllegalArgumentException
is thrown if not supported.
name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.public java.lang.Object get(java.lang.String name)
Retrieves the (potential null) content and not casting its type.
name
- the key of the field.public JsonObject put(java.lang.String name, java.lang.String value)
Stores a String
value identified by the field name.
name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.public java.lang.String getString(java.lang.String name)
Retrieves the value from the field name and casts it to String
.
name
- the name of the field.public JsonObject put(java.lang.String name, int value)
Stores a Integer
value identified by the field name.
name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.public java.lang.Integer getInt(java.lang.String name)
Retrieves the value from the field name and casts it to Integer
.
name
- the name of the field.public JsonObject put(java.lang.String name, long value)
Stores a Long
value identified by the field name.
name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.public java.lang.Long getLong(java.lang.String name)
Retrieves the value from the field name and casts it to Long
.
name
- the name of the field.public JsonObject put(java.lang.String name, double value)
Stores a Double
value identified by the field name.
name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.public java.lang.Double getDouble(java.lang.String name)
Retrieves the value from the field name and casts it to Double
.
name
- the name of the field.public JsonObject put(java.lang.String name, boolean value)
Stores a Boolean
value identified by the field name.
name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.public java.lang.Boolean getBoolean(java.lang.String name)
Retrieves the value from the field name and casts it to Boolean
.
name
- the name of the field.public JsonObject put(java.lang.String name, JsonObject value)
Stores a JsonObject
value identified by the field name.
name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.public JsonObject getObject(java.lang.String name)
Retrieves the value from the field name and casts it to JsonObject
.
name
- the name of the field.public JsonObject put(java.lang.String name, JsonArray value)
Stores a JsonArray
value identified by the field name.
name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.public JsonArray getArray(java.lang.String name)
Retrieves the value from the field name and casts it to JsonArray
.
name
- the name of the field.public java.util.Set<java.lang.String> getNames()
Returns a set of field names on the JsonObject
.
public boolean isEmpty()
Returns true if the JsonObject
is empty, false otherwise.
public java.util.Map<java.lang.String,java.lang.Object> toMap()
Creates a copy of the underlying Map
and returns it.
Map
of the content.public boolean containsKey(java.lang.String name)
Checks if the JsonObject
contains the field name.
name
- the name of the field.public boolean containsValue(java.lang.Object value)
Checks if the JsonObject
contains the value.
value
- the actual value.public int size()
The size of the JsonObject
.
public java.lang.String toString()
Converts the JsonObject
into its JSON string representation.
toString
in class java.lang.Object
JsonObject
.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object