Package com.couchbase.client.java.codec
Class Jackson3JsonSerializer
java.lang.Object
com.couchbase.client.java.codec.Jackson3JsonSerializer
- All Implemented Interfaces:
JsonSerializer
A serializer backed by a user-provided Jackson 3
JsonMapper.
In order to use this class, you must add Jackson 3 to your class path.
Make sure to register Jackson3JsonValueModule with your JsonMapper
so it can handle Couchbase JsonObject instances.
Likewise, if you're using the Encrypted annotation for
Couchbase Field-Level Encryption, make sure to register
EncryptionModule.
Example usage without Couchbase Field-Level Encryption:
JsonMapper mapper = JsonMapper.builder()
.addModule(new Jackson3JsonValueModule())
.build();
ClusterEnvironment env = ClusterEnvironment.builder()
.jsonSerializer(Jackson3JsonSerializer.create(mapper))
.build();
Example usage with Couchbase Field-Level Encryption:
CryptoManager cryptoManager = ...
JsonMapper mapper = JsonMapper.builder()
.addModule(new Jackson3JsonValueModule())
.addModule(new EncryptionModule(cryptoManager))
.build();
ClusterEnvironment env = ClusterEnvironment.builder()
.cryptoManager(cryptoManager)
.jsonSerializer(Jackson3JsonSerializer.create(mapper))
.build();
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic Jackson3JsonSerializercreate()Returns a new instance backed by a default JsonMapper without encryption support.static Jackson3JsonSerializercreate(CryptoManager cryptoManager) Returns a new instance backed by a default JsonMapper with optional encryption support.static Jackson3JsonSerializercreate(tools.jackson.databind.json.JsonMapper mapper) Returns a new instance backed by the given mapper.<T> Tdeserialize(TypeRef<T> target, byte[] input) Deserializes raw input into the target type.<T> Tdeserialize(Class<T> target, byte[] input) Deserializes raw input into the target class.byte[]Serializes the given input into its encoded byte array form.
-
Method Details
-
create
Returns a new instance backed by the given mapper.- Parameters:
mapper- the custom JsonMapper to use.
-
create
Returns a new instance backed by a default JsonMapper without encryption support.- Returns:
- the Jackson 3 JSON serializer with the default JsonMapper.
-
create
Returns a new instance backed by a default JsonMapper with optional encryption support.- Parameters:
cryptoManager- (nullable) The manager to use for activating theEncryptedannotation, or null to disable encryption support.- Returns:
- the Jackson 3 JSON serializer with the given crypto manager.
-
serialize
Description copied from interface:JsonSerializerSerializes the given input into its encoded byte array form.- Specified by:
serializein interfaceJsonSerializer- Parameters:
input- the object as input.- Returns:
- the serialized output.
-
deserialize
Description copied from interface:JsonSerializerDeserializes raw input into the target class.- Specified by:
deserializein interfaceJsonSerializer- Type Parameters:
T- the generic type to deserialize into.- Parameters:
target- the target class.input- the raw input.- Returns:
- the deserialized output.
-
deserialize
Description copied from interface:JsonSerializerDeserializes raw input into the target type.- Specified by:
deserializein interfaceJsonSerializer- Type Parameters:
T- the type to deserialize into.- Parameters:
target- the target type.input- the raw input.- Returns:
- the deserialized output.
-