@Stability.Volatile public class JsonObjectCrypto extends Object
JsonObject
for reading and writing encrypted fields.
The methods of this class mirror the methods of JsonObject
,
and behave the same way except they operate on encrypted values.
Values read via the crypto object are decrypted, and values written
via the view are encrypted.
The JsonObjectCrypto view can only see encrypted fields. Attempting to read an unencrypted field via the view has the same result as if the field does not exist.
New instances are created by calling JsonObject.crypto(com.couchbase.client.core.encryption.CryptoManager)
.
Example usage:
Collection collection = cluster.bucket("myBucket").defaultCollection(); JsonObject document = JsonObject.create(); JsonObjectCrypto crypto = document.crypto(collection); crypto.put("locationOfBuriedTreasure", "Between palm trees"); // This displays the encrypted form of the field System.out.println(document); collection.upsert("treasureMap", document); JsonObject readItBack = collection.get("treasureMap").contentAsObject(); JsonObjectCrypto readItBackCrypto = readItBack.crypto(collection); System.out.println(readItBackCrypto.getString("locationOfBuriedTreasure"));
Modifier | Constructor and Description |
---|---|
protected |
JsonObjectCrypto(JsonObject jsonObject,
CryptoManager cryptoManager,
String encrypterAlias) |
Modifier and Type | Method and Description |
---|---|
Object |
get(String fieldName) |
JsonArray |
getArray(String fieldName) |
BigDecimal |
getBigDecimal(String fieldName) |
BigInteger |
getBigInteger(String fieldName) |
Boolean |
getBoolean(String fieldName) |
Double |
getDouble(String fieldName) |
Set<String> |
getEncryptedFieldNames()
Returns the demangled names of all encrypted fields.
|
Integer |
getInt(String fieldName) |
Long |
getLong(String fieldName) |
Number |
getNumber(String fieldName) |
JsonObject |
getObject(String fieldName) |
String |
getString(String fieldName) |
Set<String> |
getUnencryptedFieldNames()
Returns the names of all unencrypted fields.
|
boolean |
hasEncryptedField(String fieldName) |
JsonObject |
object()
Returns the JsonObject bound to this crypto view.
|
JsonObjectCrypto |
put(String fieldName,
Object fieldValue) |
JsonObjectCrypto |
remove(String fieldName) |
String |
toString()
Returns the String representation of the bound JsonObject.
|
JsonObjectCrypto |
withDefaultEncrypter()
Returns a new
JsonObjectCrypto instance that uses the default encrypter. |
JsonObjectCrypto |
withEncrypter(String encrypterAlias)
Returns a new
JsonObjectCrypto instance that uses the decrypter identified by the given alias. |
JsonObjectCrypto |
withObject(JsonObject object)
Returns a new instance that is a view of the given JsonObject.
|
protected JsonObjectCrypto(JsonObject jsonObject, CryptoManager cryptoManager, String encrypterAlias)
cryptoManager
- handles the actual encryption and decryptionencrypterAlias
- (nullable) alias of the encrypter to use for writing fields,
or null for default encrypter.public JsonObjectCrypto withEncrypter(String encrypterAlias)
JsonObjectCrypto
instance that uses the decrypter identified by the given alias.public JsonObjectCrypto withDefaultEncrypter()
JsonObjectCrypto
instance that uses the default encrypter.public JsonObjectCrypto withObject(JsonObject object)
The returned instance uses the same CryptoManager
and encrypter alias as this JsonObjectCrypto instance.
public JsonObject object()
public boolean hasEncryptedField(String fieldName)
public Set<String> getEncryptedFieldNames()
public Set<String> getUnencryptedFieldNames()
public JsonObjectCrypto put(String fieldName, Object fieldValue)
public JsonObject getObject(String fieldName)
public BigDecimal getBigDecimal(String fieldName)
public BigInteger getBigInteger(String fieldName)
public JsonObjectCrypto remove(String fieldName)
Copyright © 2021 Couchbase, Inc.. All rights reserved.