public class JacksonJsonSerializer extends Object implements JsonSerializer
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();
JsonValueModule
,
EncryptionModule
Modifier and Type | Method and Description |
---|---|
static JacksonJsonSerializer |
create()
Returns a new instance backed by a default ObjectMapper
without encryption support.
|
static JacksonJsonSerializer |
create(CryptoManager cryptoManager)
Returns a new instance backed by a default ObjectMapper
with optional encryption support.
|
static JacksonJsonSerializer |
create(com.fasterxml.jackson.databind.ObjectMapper mapper)
Returns a new instance backed by a the given ObjectMapper.
|
<T> T |
deserialize(Class<T> target,
byte[] input)
Deserializes raw input into the target class.
|
<T> T |
deserialize(TypeRef<T> target,
byte[] input)
Deserializes raw input into the target type.
|
byte[] |
serialize(Object input)
Serializes the given input into its encoded byte array form.
|
public static JacksonJsonSerializer create(com.fasterxml.jackson.databind.ObjectMapper mapper)
public static JacksonJsonSerializer create()
public static JacksonJsonSerializer create(CryptoManager cryptoManager)
cryptoManager
- (nullable) The manager to use for activating the
Encrypted
annotation, or null to disable encryption support.public byte[] serialize(Object input)
JsonSerializer
serialize
in interface JsonSerializer
input
- the object as input.public <T> T deserialize(Class<T> target, byte[] input)
JsonSerializer
deserialize
in interface JsonSerializer
T
- the generic type to deserialize into.target
- the target class.input
- the raw input.public <T> T deserialize(TypeRef<T> target, byte[] input)
JsonSerializer
deserialize
in interface JsonSerializer
T
- the type to deserialize into.target
- the target type.input
- the raw input.Copyright © 2020 Couchbase, Inc.. All rights reserved.