Package com.couchbase.client.java.codec
Class JacksonJsonSerializer
java.lang.Object
com.couchbase.client.java.codec.JacksonJsonSerializer
- All Implemented Interfaces:
- JsonSerializer
A serializer backed by a user-provided Jackson 
ObjectMapper.
 In order to use this class you must add Jackson to your class path.
 Make sure to register JsonValueModule with your ObjectMapper
 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:
 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:
- 
Nested Class SummaryNested Classes
- 
Method SummaryModifier and TypeMethodDescriptionstatic 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 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 voidThrows something if the user-provided Jackson library is absent or broken.byte[]Serializes the given input into its encoded byte array form.
- 
Method Details- 
createReturns a new instance backed by the given ObjectMapper.- Parameters:
- mapper- the custom ObjectMapper to use.
- Returns:
- the Jackson JSON serializer with a custom object mapper.
 
- 
createReturns a new instance backed by a default ObjectMapper without encryption support.- Returns:
- the Jackson JSON serializer with the default object mapper.
 
- 
createReturns a new instance backed by a default ObjectMapper with optional encryption support.- Parameters:
- cryptoManager- (nullable) The manager to use for activating the- Encryptedannotation, or null to disable encryption support.
- Returns:
- the Jackson JSON serializer with a provided crypto manager.
 
- 
serializeDescription copied from interface:JsonSerializerSerializes the given input into its encoded byte array form.- Specified by:
- serializein interface- JsonSerializer
- Parameters:
- input- the object as input.
- Returns:
- the serialized output.
 
- 
deserializeDescription copied from interface:JsonSerializerDeserializes raw input into the target class.- Specified by:
- deserializein interface- JsonSerializer
- Type Parameters:
- T- the generic type to deserialize into.
- Parameters:
- target- the target class.
- input- the raw input.
- Returns:
- the deserialized output.
 
- 
deserializeDescription copied from interface:JsonSerializerDeserializes raw input into the target type.- Specified by:
- deserializein interface- JsonSerializer
- Type Parameters:
- T- the type to deserialize into.
- Parameters:
- target- the target type.
- input- the raw input.
- Returns:
- the deserialized output.
 
- 
preflightCheckThrows something if the user-provided Jackson library is absent or broken.- Throws:
- Throwable- if JacksonJsonSerializer should not be used.
- Implementation Note:
- Looking for ObjectMapper on the class path is not sufficient; we've seen at least one case where ObjectMapper was present but its dependencies were missing.
 
 
-