public class JsonObject extends JsonValue implements Serializable
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 | Field and Description |
---|---|
static String |
ENCRYPTION_PREFIX
Encryption prefix
|
Modifier and Type | Method and Description |
---|---|
void |
clearEncryptionPaths()
Clear the encryption paths
|
boolean |
containsKey(String name)
Checks if the
JsonObject contains the field name. |
boolean |
containsValue(Object value)
Checks if the
JsonObject contains the value. |
static JsonObject |
create()
Creates a empty
JsonObject . |
static JsonObject |
empty()
Creates a empty
JsonObject . |
Map<String,String> |
encryptionPathInfo()
Get the encryption list to merge path with parent
|
boolean |
equals(Object o) |
static JsonObject |
from(Map<String,?> mapData)
Constructs a
JsonObject from a Map<String, ?> . |
static JsonObject |
fromJson(String s)
Static method to create a
JsonObject from a JSON String . |
Object |
get(String name)
Retrieves the (potential null) content and not casting its type.
|
Object |
getAndDecrypt(String name,
String providerName)
Retrieve and decrypt content and not casting its type
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc.
|
JsonArray |
getAndDecryptArray(String name,
String providerName)
Retrieves the decrypted value from the field name and casts it to
JsonArray . |
BigDecimal |
getAndDecryptBigDecimal(String name,
String providerName)
Retrieves the decrypted value from the field name and casts it to
BigDecimal . |
BigInteger |
getAndDecryptBigInteger(String name,
String providerName)
Retrieves the decrypted value from the field name and casts it to
BigInteger . |
Boolean |
getAndDecryptBoolean(String name,
String providerName)
Retrieves the decrypted value from the field name and casts it to
Boolean . |
Double |
getAndDecryptDouble(String name,
String providerName)
Retrieves the value from the field name and casts it to
Double . |
Integer |
getAndDecryptInt(String name,
String providerName)
Retrieves the decrypted value from the field name and casts it to
Integer . |
Long |
getAndDecryptLong(String name,
String providerName)
Retrieves the decrypted value from the field name and casts it to
Long . |
Number |
getAndDecryptNumber(String name,
String providerName)
Retrieves the decrypted value from the field name and casts it to
Number . |
JsonObject |
getAndDecryptObject(String name,
String providerName)
Retrieves the decrypted value from the field name and casts it to
JsonObject . |
String |
getAndDecryptString(String name,
String providerName)
Retrieves the decrypted value from the field name and casts it to
String . |
JsonArray |
getArray(String name)
Retrieves the value from the field name and casts it to
JsonArray . |
BigDecimal |
getBigDecimal(String name)
Retrieves the value from the field name and casts it to
BigDecimal . |
BigInteger |
getBigInteger(String name)
Retrieves the value from the field name and casts it to
BigInteger . |
Boolean |
getBoolean(String name)
Retrieves the value from the field name and casts it to
Boolean . |
CryptoManager |
getCryptoManager()
Get the encryption configuration for decryption
|
Double |
getDouble(String name)
Retrieves the value from the field name and casts it to
Double . |
Integer |
getInt(String name)
Retrieves the value from the field name and casts it to
Integer . |
Long |
getLong(String name)
Retrieves the value from the field name and casts it to
Long . |
Set<String> |
getNames()
Returns a set of field names on the
JsonObject . |
Number |
getNumber(String name)
Retrieves the value from the field name and casts it to
Number . |
JsonObject |
getObject(String name)
Retrieves the value from the field name and casts it to
JsonObject . |
String |
getString(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. |
boolean |
isEncrypted(String name)
Returns true if the field is encrypted.
|
JsonObject |
put(String name,
boolean value)
Stores a
Boolean value identified by the field name. |
JsonObject |
put(String name,
double value)
Stores a
Double value identified by the field name. |
JsonObject |
put(String name,
int value)
Stores a
Integer value identified by the field name. |
JsonObject |
put(String name,
JsonArray value)
Stores a
JsonArray value identified by the field name. |
JsonObject |
put(String name,
JsonObject value)
Stores a
JsonObject value identified by the field name. |
JsonObject |
put(String name,
List<?> value)
Stores a
JsonArray value identified by the field name. |
JsonObject |
put(String name,
long value)
Stores a
Long value identified by the field name. |
JsonObject |
put(String name,
Map<String,?> value)
Attempt to convert a
Map to a JsonObject value and store it, identified by the field name. |
JsonObject |
put(String name,
Number value)
Stores a
Number value identified by the field name. |
JsonObject |
put(String name,
Object value)
Stores a
Object value identified by the field name. |
JsonObject |
put(String name,
String value)
Stores a
String value identified by the field name. |
JsonObject |
putAndEncrypt(String name,
boolean value,
String providerName)
Stores a
Boolean value as encrypted identified by the field name. |
JsonObject |
putAndEncrypt(String name,
double value,
String providerName)
Stores a
Double value as encrypted identified by the field name. |
JsonObject |
putAndEncrypt(String name,
int value,
String providerName)
Stores a
Integer value as encrypted identified by the field name. |
JsonObject |
putAndEncrypt(String name,
JsonArray value,
String providerName)
Stores a
JsonArray value as encrypted identified by the field name. |
JsonObject |
putAndEncrypt(String name,
JsonObject value,
String providerName)
Stores a
JsonObject value as encrypted identified by the field name. |
JsonObject |
putAndEncrypt(String name,
List<?> value,
String providerName)
Stores a
JsonArray value as encrypted identified by the field name. |
JsonObject |
putAndEncrypt(String name,
long value,
String providerName)
Stores a
Long value as encrypted identified by the field name. |
JsonObject |
putAndEncrypt(String name,
Map<String,?> value,
String providerName)
Attempt to convert a
Map to a JsonObject value and store it,
as encrypted identified by the field name. |
JsonObject |
putAndEncrypt(String name,
Number value,
String providerName)
Stores a
Number value as encrypted identified by the field name. |
JsonObject |
putAndEncrypt(String name,
Object value,
String providerName)
Stores the
Object value as encrypted identified by the field name. |
JsonObject |
putAndEncrypt(String name,
String value,
String providerName)
Stores a
String value as encrypted identified by the field name. |
JsonObject |
putNull(String name)
Store a null value identified by the field's name.
|
JsonObject |
putNullAndEncrypt(String name,
String providerName)
Store a null value as encrypted identified by the field's name.
|
JsonObject |
removeKey(String name)
Removes an entry from the
JsonObject . |
void |
setCryptoManager(CryptoManager cryptoManager)
Set the encryption configuration for decryption
|
int |
size()
The size of the
JsonObject . |
Map<String,Object> |
toDecryptedMap(String providerName)
Transforms the
JsonObject into a Map . |
String |
toDecryptedString(String providerName)
Converts the
JsonObject into its decrypted JSON string representation. |
Map<String,Object> |
toMap()
Transforms the
JsonObject into a Map . |
String |
toString()
Converts the
JsonObject into its JSON string representation. |
public static final String ENCRYPTION_PREFIX
public static JsonObject empty()
JsonObject
.JsonObject
.public static JsonObject create()
JsonObject
.JsonObject
.public static JsonObject from(Map<String,?> mapData)
JsonObject
from a Map<String, ?>
.
This is only possible if the given Map is well formed, that is it contains non null
keys, and all values are of a supported type.
A null input Map or null key will lead to a NullPointerException
being thrown.
If any unsupported value is present in the Map, an IllegalArgumentException
will be thrown.
*Sub Maps and Lists*
If possible, Maps and Lists contained in mapData will be converted to JsonObject and
JsonArray respectively. However, same restrictions apply. Any non-convertible collection
will raise a ClassCastException
. If the sub-conversion raises an exception (like an
IllegalArgumentException) then it is put as cause for the ClassCastException.mapData
- the Map to convert to a JsonObjectIllegalArgumentException
- in case one or more unsupported values are presentNullPointerException
- in case a null map is provided or if it contains a null keyClassCastException
- if map contains a sub-Map or sub-List not supported (see above)public static JsonObject fromJson(String s)
JsonObject
from a JSON String
.
The string is expected to be a valid JSON object representation (eg. starting with a '{').s
- the JSON String to convert to a JsonObject
.JsonObject
.IllegalArgumentException
- if the conversion cannot be done.public JsonObject put(String name, Object value)
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 JsonObject putAndEncrypt(String name, Object value, String providerName)
Object
value as encrypted identified by the field name.
Note that the value is checked and a IllegalArgumentException
is thrown if not supported.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the JSON field.value
- the value of the JSON field.providerName
- Crypto provider name for encryption.JsonObject
.public Object get(String name)
name
- the key of the field.public Object getAndDecrypt(String name, String providerName) throws Exception
name
- the key of the fieldproviderName
- the crypto algorithm provider nameException
public JsonObject put(String name, String value)
String
value identified by the field name.name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.public JsonObject putAndEncrypt(String name, String value, String providerName)
String
value as encrypted identified by the field name.name
- the name of the JSON field.value
- the value of the JSON field.providerName
- the crypto provider name for encryption.JsonObject
.public String getString(String name)
String
.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the field.public String getAndDecryptString(String name, String providerName) throws Exception
String
.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the field.providerName
- the crypto provider name for decryption.Exception
public JsonObject put(String name, int value)
Integer
value identified by the field name.name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.public JsonObject putAndEncrypt(String name, int value, String providerName)
Integer
value as encrypted identified by the field name.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the JSON field.value
- the value of the JSON field.providerName
- Crypto provider name for encryption.JsonObject
.public Integer getInt(String name)
Integer
.
Note that if value was stored as another numerical type, some truncation or rounding may occur.name
- the name of the field.@InterfaceStability.Committed public Integer getAndDecryptInt(String name, String providerName) throws Exception
Integer
.
Note that if value was stored as another numerical type, some truncation or rounding may occur.name
- the name of the field.providerName
- crypto provider name for decryption.Exception
public JsonObject put(String name, long value)
Long
value identified by the field name.name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.public JsonObject putAndEncrypt(String name, long value, String providerName)
Long
value as encrypted identified by the field name.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the JSON field.value
- the value of the JSON field.providerName
- Crypto provider name for encryption.JsonObject
.public Long getLong(String name)
Long
.
Note that if value was stored as another numerical type, some truncation or rounding may occur.name
- the name of the field.public Long getAndDecryptLong(String name, String providerName) throws Exception
Long
.
Note that if value was stored as another numerical type, some truncation or rounding may occur.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the field.providerName
- the crypto provider name for decryptionException
public JsonObject put(String name, double value)
Double
value identified by the field name.name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.public JsonObject putAndEncrypt(String name, double value, String providerName)
Double
value as encrypted identified by the field name.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the JSON field.value
- the value of the JSON field.providerName
- Crypto provider name for encryption.JsonObject
.public Double getDouble(String name)
Double
.
Note that if value was stored as another numerical type, some truncation or rounding may occur.name
- the name of the field.public Double getAndDecryptDouble(String name, String providerName) throws Exception
Double
.
Note that if value was stored as another numerical type, some truncation or rounding may occur.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the field.providerName
- the crypto provider name for decryptionException
public JsonObject put(String name, boolean value)
Boolean
value identified by the field name.name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.public JsonObject putAndEncrypt(String name, boolean value, String providerName)
Boolean
value as encrypted identified by the field name.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the JSON field.value
- the value of the JSON field.providerName
- Crypto provider name for encryption.JsonObject
.public Boolean getBoolean(String name)
Boolean
.name
- the name of the field.public Boolean getAndDecryptBoolean(String name, String providerName) throws Exception
Boolean
.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the field.providerName
- the provider name of the field.Exception
public JsonObject put(String name, JsonObject value)
JsonObject
value identified by the field name.name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.public JsonObject putAndEncrypt(String name, JsonObject value, String providerName)
JsonObject
value as encrypted identified by the field name.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the JSON field.value
- the value of the JSON field.providerName
- Crypto provider name for encryption.JsonObject
.public JsonObject put(String name, Map<String,?> value)
Map
to a JsonObject
value and store it, identified by the field name.name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.from(Map)
public JsonObject putAndEncrypt(String name, Map<String,?> value, String providerName)
Map
to a JsonObject
value and store it,
as encrypted identified by the field name.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the JSON field.value
- the value of the JSON field.providerName
- Crypto provider name for encryption.JsonObject
.from(Map)
public JsonObject getObject(String name)
JsonObject
.name
- the name of the field.public JsonObject getAndDecryptObject(String name, String providerName) throws Exception
JsonObject
.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the field.providerName
- Crypto provider name for decryptionException
public JsonObject put(String name, JsonArray value)
JsonArray
value identified by the field name.name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.public JsonObject putAndEncrypt(String name, JsonArray value, String providerName)
JsonArray
value as encrypted identified by the field name.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the JSON field.value
- the value of the JSON field.providerName
- the crypto provider name for encryption.JsonObject
.public JsonObject put(String name, Number value)
Number
value identified by the field name.name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.public JsonObject putAndEncrypt(String name, Number value, String providerName)
Number
value as encrypted identified by the field name.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the JSON field.value
- the value of the JSON field.providerName
- Crypto provider name for encryption.JsonObject
.public JsonObject put(String name, List<?> value)
JsonArray
value identified by the field name.name
- the name of the JSON field.value
- the value of the JSON field.JsonObject
.public JsonObject putAndEncrypt(String name, List<?> value, String providerName)
JsonArray
value as encrypted identified by the field name.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the JSON field.value
- the value of the JSON field.providerName
- the crypto provider name for encryption.JsonObject
.public JsonArray getArray(String name)
JsonArray
.name
- the name of the field.public JsonArray getAndDecryptArray(String name, String providerName) throws Exception
JsonArray
.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the field.providerName
- crypto provider name for decryption.Exception
public BigInteger getBigInteger(String name)
BigInteger
.name
- the name of the field.public BigInteger getAndDecryptBigInteger(String name, String providerName) throws Exception
BigInteger
.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the field.providerName
- crypto provider name for decryption.Exception
public BigDecimal getBigDecimal(String name)
BigDecimal
.name
- the name of the field.public BigDecimal getAndDecryptBigDecimal(String name, String providerName) throws Exception
BigDecimal
.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the field.providerName
- crypto provider for decryptionException
public Number getNumber(String name)
Number
.name
- the name of the field.public Number getAndDecryptNumber(String name, String providerName) throws Exception
Number
.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- the name of the field.providerName
- the crypto provider name for decryptionException
public JsonObject putNull(String name)
put(String, Object)
with either
JsonValue.NULL
or a null value explicitly cast to Object.name
- The null field's name.JsonObject
public JsonObject putNullAndEncrypt(String name, String providerName)
put(String, Object)
with either
JsonValue.NULL
or a null value explicitly cast to Object.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.name
- The null field's name.providerName
- Crypto provider name for encryption.JsonObject
public JsonObject removeKey(String name)
JsonObject
.name
- the name of the field to removeJsonObject
public Set<String> getNames()
JsonObject
.public boolean isEmpty()
JsonObject
is empty, false otherwise.public Map<String,Object> toMap()
JsonObject
into a Map
. The resulting
map is not backed by this JsonObject
, and all sub-objects or
sub-arrays (JsonArray
) are also recursively converted to
maps and lists, respectively.Map
.public Map<String,Object> toDecryptedMap(String providerName) throws Exception
JsonObject
into a Map
. The resulting
map is not backed by this JsonObject
, and all sub-objects or
sub-arrays (JsonArray
) are also recursively converted to
maps and lists, respectively. The encrypted values are decrypted.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.public boolean containsKey(String name)
JsonObject
contains the field name.name
- the name of the field.public boolean containsValue(Object value)
JsonObject
contains the value.value
- the actual value.public int size()
JsonObject
.public boolean isEncrypted(String name)
name
- the key name of the field.@InterfaceAudience.Private public Map<String,String> encryptionPathInfo()
@InterfaceStability.Committed @InterfaceAudience.Private public void clearEncryptionPaths()
@InterfaceAudience.Private public void setCryptoManager(CryptoManager cryptoManager)
@InterfaceAudience.Private public CryptoManager getCryptoManager()
public String toString()
JsonObject
into its JSON string representation.toString
in class Object
JsonObject
.public String toDecryptedString(String providerName) throws Exception
JsonObject
into its decrypted JSON string representation.
Note: Use of the Field Level Encryption functionality provided in the
com.couchbase.client.encryption namespace provided by Couchbase is
subject to the Couchbase Inc. Enterprise Subscription License Agreement
at https://www.couchbase.com/ESLA-11132015.JsonObject
.Exception
Copyright © 2015 Couchbase, Inc.