Package com.couchbase.client.java.json
Class JsonObjectCrypto
- java.lang.Object
-
- com.couchbase.client.java.json.JsonObjectCrypto
-
@Volatile public class JsonObjectCrypto extends Object
A view of a CouchbaseJsonObjectfor 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"));
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedJsonObjectCrypto(JsonObject jsonObject, CryptoManager cryptoManager, String encrypterAlias)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectget(String fieldName)JsonArraygetArray(String fieldName)BigDecimalgetBigDecimal(String fieldName)BigIntegergetBigInteger(String fieldName)BooleangetBoolean(String fieldName)DoublegetDouble(String fieldName)Set<String>getEncryptedFieldNames()Returns the demangled names of all encrypted fields.IntegergetInt(String fieldName)LonggetLong(String fieldName)NumbergetNumber(String fieldName)JsonObjectgetObject(String fieldName)StringgetString(String fieldName)Set<String>getUnencryptedFieldNames()Returns the names of all unencrypted fields.booleanhasEncryptedField(String fieldName)JsonObjectobject()Returns the JsonObject bound to this crypto view.JsonObjectCryptoput(String fieldName, Object fieldValue)JsonObjectCryptoremove(String fieldName)StringtoString()Returns the String representation of the bound JsonObject.JsonObjectCryptowithDefaultEncrypter()Returns a newJsonObjectCryptoinstance that uses the default encrypter.JsonObjectCryptowithEncrypter(String encrypterAlias)Returns a newJsonObjectCryptoinstance that uses the decrypter identified by the given alias.JsonObjectCryptowithObject(JsonObject object)Returns a new instance that is a view of the given JsonObject.
-
-
-
Constructor Detail
-
JsonObjectCrypto
protected JsonObjectCrypto(JsonObject jsonObject, CryptoManager cryptoManager, String encrypterAlias)
- Parameters:
cryptoManager- handles the actual encryption and decryptionencrypterAlias- (nullable) alias of the encrypter to use for writing fields, or null for default encrypter.
-
-
Method Detail
-
withEncrypter
public JsonObjectCrypto withEncrypter(String encrypterAlias)
Returns a newJsonObjectCryptoinstance that uses the decrypter identified by the given alias.
-
withDefaultEncrypter
public JsonObjectCrypto withDefaultEncrypter()
Returns a newJsonObjectCryptoinstance that uses the default encrypter.
-
withObject
public JsonObjectCrypto withObject(JsonObject object)
Returns a new instance that is a view of the given JsonObject.The returned instance uses the same
CryptoManagerand encrypter alias as this JsonObjectCrypto instance.
-
object
public JsonObject object()
Returns the JsonObject bound to this crypto view.
-
hasEncryptedField
public boolean hasEncryptedField(String fieldName)
-
getEncryptedFieldNames
public Set<String> getEncryptedFieldNames()
Returns the demangled names of all encrypted fields.
-
getUnencryptedFieldNames
public Set<String> getUnencryptedFieldNames()
Returns the names of all unencrypted fields.
-
put
public JsonObjectCrypto put(String fieldName, Object fieldValue)
-
getObject
public JsonObject getObject(String fieldName)
-
getBigDecimal
public BigDecimal getBigDecimal(String fieldName)
-
getBigInteger
public BigInteger getBigInteger(String fieldName)
-
remove
public JsonObjectCrypto remove(String fieldName)
-
-