Package com.couchbase.client.java.codec
Class JacksonJsonSerializer
- java.lang.Object
-
- com.couchbase.client.java.codec.JacksonJsonSerializer
-
- All Implemented Interfaces:
JsonSerializer
public class JacksonJsonSerializer extends Object implements JsonSerializer
A serializer backed by a user-provided JacksonObjectMapper.In order to use this class you must add Jackson to your class path.
Make sure to register
JsonValueModulewith yourObjectMapperso it can handle CouchbaseJsonObjectinstances.Likewise, if you're using the
Encryptedannotation for Couchbase Field-Level Encryption, make sure to registerEncryptionModule.Example usage without Couchbase Field-Level Encryption:
ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JsonValueModule()); ClusterEnvironment env = ClusterEnvironment.builder() .jsonSerializer(new JacksonJsonSerializer(mapper)) .build();Example usage with Couchbase Field-Level Encryption:
CryptoManager cryptoManager = ... ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JsonValueModule()); mapper.registerModule(new EncryptionModule(cryptoManager)); ClusterEnvironment env = ClusterEnvironment.builder() .cryptoManager(cryptoManager) .jsonSerializer(new JacksonJsonSerializer(mapper)) .build();- See Also:
JsonValueModule,EncryptionModule
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJacksonJsonSerializer.PreflightCheckSubject
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static JacksonJsonSerializercreate()Returns a new instance backed by a default ObjectMapper without encryption support.static JacksonJsonSerializercreate(CryptoManager cryptoManager)Returns a new instance backed by a default ObjectMapper with optional encryption support.static JacksonJsonSerializercreate(com.fasterxml.jackson.databind.ObjectMapper mapper)Returns a new instance backed by a the given ObjectMapper.<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.static voidpreflightCheck()Throws something if the user-provided Jackson library is absent or broken.byte[]serialize(Object input)Serializes the given input into its encoded byte array form.
-
-
-
Method Detail
-
create
public static JacksonJsonSerializer create(com.fasterxml.jackson.databind.ObjectMapper mapper)
Returns a new instance backed by a the given ObjectMapper.
-
create
public static JacksonJsonSerializer create()
Returns a new instance backed by a default ObjectMapper without encryption support.
-
create
public static JacksonJsonSerializer create(CryptoManager cryptoManager)
Returns a new instance backed by a default ObjectMapper with optional encryption support.- Parameters:
cryptoManager- (nullable) The manager to use for activating theEncryptedannotation, or null to disable encryption support.
-
serialize
public byte[] serialize(Object input)
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
public <T> T deserialize(Class<T> target, byte[] input)
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
public <T> T deserialize(TypeRef<T> target, byte[] input)
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.
-
-