public class JsonObject extends JsonStructure implements java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.Object>>, android.os.Parcelable
Modifier and Type | Field and Description |
---|---|
static android.os.Parcelable.Creator<JsonObject> |
CREATOR |
protected java.util.Map<java.lang.String,java.lang.Object> |
map |
Modifier | Constructor and Description |
---|---|
|
JsonObject()
Creates a new JsonObject with no mappings
|
protected |
JsonObject(JsonObject object) |
protected |
JsonObject(android.os.Parcel source) |
Modifier and Type | Method and Description |
---|---|
JsonObject |
clear()
Removes all the mappings from this object
|
boolean |
contains(java.lang.String name)
Checks if this object contains a mapping with
name key |
JsonObject |
copy()
Creates a deeep copy of this structure.
|
static JsonObject |
decode(java.lang.String json)
Decodes the
json string passed as parameter. |
int |
describeContents() |
java.lang.String |
encode()
Encodes this structure to it's json representation
|
boolean |
equals(java.lang.Object o) |
java.util.Set<java.lang.String> |
fields()
Returns a
Set of all the keys contained in this document |
static JsonObject |
from(android.content.ContentValues values)
Creates a new JsonObject based on values contained in the
ContentValues |
<T> T |
get(java.lang.String name) |
JsonArray |
getArray(java.lang.String name)
|
JsonArray |
getArray(java.lang.String name,
JsonArray otherwise)
|
byte[] |
getBinary(java.lang.String name)
Returns the value mapped to
name as a byte[] array
or null if the mapping is absent. |
byte[] |
getBinary(java.lang.String name,
byte[] otherwise)
Returns the value mapped to
name as a byte[] array
or otherwise if the mapping is absent. |
java.lang.Boolean |
getBoolean(java.lang.String name)
Returns the value mapped to
name as a Boolean
or null if the mapping is absent. |
boolean |
getBoolean(java.lang.String name,
boolean otherwise)
Returns the value mapped to
name as a boolean
or otherwise if the mapping is absent. |
java.lang.Double |
getDouble(java.lang.String name)
Returns the value mapped to
name as a Double
or null if the mapping is absent. |
double |
getDouble(java.lang.String name,
double otherwise)
Returns the value mapped to
name as a double
or otherwise if the mapping is absent. |
java.lang.Float |
getFloat(java.lang.String name)
Returns the value mapped to
name as a Float
or null if the mapping is absent. |
float |
getFloat(java.lang.String name,
float otherwise)
Returns the value mapped to
name as a float
or otherwise if the mapping is absent. |
java.lang.Integer |
getInt(java.lang.String name)
Returns the value mapped to
name as a Integer
or null if the mapping is absent. |
int |
getInt(java.lang.String name,
int otherwise)
Returns the value mapped to
name as a int
or otherwise if the mapping is absent. |
java.lang.Long |
getLong(java.lang.String name)
Returns the value mapped to
name as a Long
or null if the mapping is absent. |
long |
getLong(java.lang.String name,
long otherwise)
Returns the value mapped to
name as a long
or otherwise if the mapping is absent. |
JsonObject |
getObject(java.lang.String name)
|
JsonObject |
getObject(java.lang.String name,
JsonObject otherwise)
|
java.lang.String |
getString(java.lang.String name)
Returns the value mapped to
name as a String
or null if the mapping is absent. |
java.lang.String |
getString(java.lang.String name,
java.lang.String otherwise)
Returns the value mapped to
name as a String
or otherwise if the mapping is absent. |
JsonStructure |
getStructure(java.lang.String name)
|
JsonStructure |
getStructure(java.lang.String name,
JsonStructure otherwise)
|
int |
hashCode() |
boolean |
isNull(java.lang.String name)
Checks if
name maps explicitly to null |
java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.Object>> |
iterator()
Returns an
Iterator of the mappings contained
in this object |
JsonObject |
merge(JsonObject other)
Merges the mappings of
other in this object. |
JsonObject |
mergeMissing(JsonObject other)
Merges the mappings of
other in this object. |
static JsonObject |
of(java.lang.Object... keyValues) |
protected void |
onModify() |
JsonObject |
put(java.lang.String name,
boolean value)
Associate
name key to the boolean value
in this object. |
JsonObject |
put(java.lang.String name,
byte[] value)
Associate
name key to the byte[] value
in this object. |
JsonObject |
put(java.lang.String name,
double value)
Associate
name key to the double value
in this object. |
JsonObject |
put(java.lang.String name,
JsonArray value)
|
JsonObject |
put(java.lang.String name,
JsonObject value)
|
JsonObject |
put(java.lang.String name,
long value)
Associate
name key to the long value
in this object. |
JsonObject |
put(java.lang.String name,
java.lang.String value)
Associate
name key to the String value
in this object. |
JsonObject |
putNull(java.lang.String name)
Puts an explicit mapping to from
name to null
in this object. |
java.lang.Object |
remove(java.lang.String name)
Removes the mapping with
name key from the object. |
int |
size()
Returns the number of mappings in this object
|
java.lang.String |
toString() |
int |
typeAt(java.lang.String key) |
JsonArray |
values()
Returns the values contained in this structure as a
JsonArray |
JsonObject |
without(java.lang.String name)
Removes the mapping with
name key from the object. |
void |
writeToParcel(android.os.Parcel dest,
int flags) |
asArray, asObject, isArray, isObject
public static final android.os.Parcelable.Creator<JsonObject> CREATOR
protected java.util.Map<java.lang.String,java.lang.Object> map
public JsonObject()
protected JsonObject(android.os.Parcel source)
protected JsonObject(JsonObject object)
public JsonObject copy()
JsonStructure
copy
in class JsonStructure
public static JsonObject from(android.content.ContentValues values)
ContentValues
values
- non null valuespublic static JsonObject of(java.lang.Object... keyValues)
public static JsonObject decode(java.lang.String json)
json
string passed as parameter.json
- the string to decodeJsonException
- if an error happens during parsing of the stringpublic JsonObject put(java.lang.String name, java.lang.String value)
name
key to the String
value
in this object.name
- a non null
keyvalue
- a String
valuepublic JsonObject put(java.lang.String name, boolean value)
name
key to the boolean
value
in this object.name
- a non null
keyvalue
- a boolean
valuepublic JsonObject put(java.lang.String name, long value)
name
key to the long
value
in this object.name
- a non null
keyvalue
- a long
valuepublic JsonObject put(java.lang.String name, double value)
name
key to the double
value
in this object.name
- a non null
keyvalue
- a double
valuepublic JsonObject putNull(java.lang.String name)
name
to null
in this object.
This is different from not having the mapping at all, to completely remove
the mapping use instead JsonObject.remove(String)
name
- a non null
keyJsonObject.remove(String)
public JsonObject put(java.lang.String name, JsonArray value)
name
- a non null
keyvalue
- a JsonArray
or nullprotected void onModify()
public JsonObject put(java.lang.String name, JsonObject value)
name
- a non null
keyvalue
- a JsonObject
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String encode()
JsonStructure
encode
in class JsonStructure
public java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.Object>> iterator()
Iterator
of the mappings contained
in this objectiterator
in interface java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.Object>>
public int describeContents()
describeContents
in interface android.os.Parcelable
public void writeToParcel(android.os.Parcel dest, int flags)
writeToParcel
in interface android.os.Parcelable
public JsonObject clear()
clear
in class JsonStructure
public boolean contains(java.lang.String name)
name
keyname
- a non null
keytrue
if the object contains the mapping false
otherwisepublic <T> T get(java.lang.String name)
public JsonArray getArray(java.lang.String name)
name
- a non null
keyname
or null
public JsonArray getArray(java.lang.String name, JsonArray otherwise)
name
- a non null
keyotherwise
- a default valuename
or otherwise
public byte[] getBinary(java.lang.String name)
name
as a byte[]
array
or null
if the mapping is absent.name
- a non null
keyname
or null
public byte[] getBinary(java.lang.String name, byte[] otherwise)
name
as a byte[]
array
or otherwise
if the mapping is absent.name
- a non null
keyotherwise
- a default valuename
or otherwise
public java.lang.Boolean getBoolean(java.lang.String name)
name
as a Boolean
or null
if the mapping is absent.name
- a non null
keyname
or null
public boolean getBoolean(java.lang.String name, boolean otherwise)
name
as a boolean
or otherwise
if the mapping is absent.otherwise
- a boolean
defaultname
- a non null
keyname
or otherwise
public double getDouble(java.lang.String name, double otherwise)
name
as a double
or otherwise
if the mapping is absent.otherwise
- a double
defaultname
- a non null
keyname
or otherwise
public java.lang.Float getFloat(java.lang.String name)
name
as a Float
or null
if the mapping is absent.name
- a non null
keyname
or null
public java.lang.Double getDouble(java.lang.String name)
name
as a Double
or null
if the mapping is absent.name
- a non null
keyname
or null
public float getFloat(java.lang.String name, float otherwise)
name
as a float
or otherwise
if the mapping is absent.otherwise
- a float
defaultname
- a non null
keyname
or otherwise
public java.lang.Integer getInt(java.lang.String name)
name
as a Integer
or null
if the mapping is absent.name
- a non null
keyname
or null
public java.lang.Long getLong(java.lang.String name)
name
as a Long
or null
if the mapping is absent.name
- a non null
keyname
or null
public int getInt(java.lang.String name, int otherwise)
name
as a int
or otherwise
if the mapping is absent.otherwise
- a int
defaultname
- a non null
keyname
or otherwise
public long getLong(java.lang.String name, long otherwise)
name
as a long
or otherwise
if the mapping is absent.otherwise
- a long
defaultname
- a non null
keyname
or otherwise
public JsonObject getObject(java.lang.String name)
name
- a non null
keyname
or null
public JsonObject getObject(java.lang.String name, JsonObject otherwise)
name
- a non null
keyotherwise
- a default valuename
or otherwise
public java.lang.String getString(java.lang.String name)
name
as a String
or null
if the mapping is absent.name
- a non null
keyname
or null
public java.lang.String getString(java.lang.String name, java.lang.String otherwise)
name
as a String
or otherwise
if the mapping is absent.name
- a non null
keyotherwise
- a default valuename
or otherwise
public JsonStructure getStructure(java.lang.String name)
name
- a non null
keyname
or null
public JsonStructure getStructure(java.lang.String name, JsonStructure otherwise)
name
- a non null
keyotherwise
- a default valuename
or otherwise
public int typeAt(java.lang.String key)
public boolean isNull(java.lang.String name)
name
maps explicitly to null
name
- a non null
keytrue
if the object contains a mapping from name
to null
false
otherwisepublic JsonObject merge(JsonObject other)
other
in this object.other
- an object to merge inpublic JsonObject mergeMissing(JsonObject other)
other
in this object.
Fields that are present in this object are not overwritten.other
- an object to merge inpublic java.util.Set<java.lang.String> fields()
Set
of all the keys contained in this documentpublic JsonObject put(java.lang.String name, byte[] value)
name
key to the byte[]
value
in this object.
Note that binary data is encoded using base64 and added as strings in the object.name
- a non null
keyvalue
- a byte[]
arraypublic int size()
public JsonArray values()
JsonStructure
JsonArray
values
in class JsonStructure
public JsonObject without(java.lang.String name)
name
key from the object.name
- a non null
keypublic java.lang.Object remove(java.lang.String name)
name
key from the object.name
- a non null
keyname
if present or null