Class Jackson3JsonSerializer

java.lang.Object
com.couchbase.client.java.codec.Jackson3JsonSerializer
All Implemented Interfaces:
JsonSerializer

public class Jackson3JsonSerializer extends Object implements 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.

Example usage:

 var mapper = JsonMapper.builder().build();
 var serializer = Jackson3JsonSerializer.create(mapper);

 // Set as default serializer when connecting
 Cluster cluster = Cluster.connect(
   connectionString,
   ClusterOptions.clusterOptions(username, password)
     .environment(env -> env
       .jsonSerializer(serializer)
     )
 );
 
WARNING: This serializer ignores the Encrypted annotation for automatic Field-Level Encryption (FLE). Automatic FLE with data binding requires using JacksonJsonSerializer and Jackson 2, or the default serializer which uses a repackaged version of Jackson 2.
  • Method Details

    • create

      public static Jackson3JsonSerializer create(tools.jackson.databind.json.JsonMapper mapper)
      Returns a new instance backed by the given mapper.
      Parameters:
      mapper - the custom JsonMapper to use.
    • serialize

      public byte[] serialize(Object input)
      Description copied from interface: JsonSerializer
      Serializes the given input into its encoded byte array form.
      Specified by:
      serialize in interface JsonSerializer
      Parameters:
      input - the object as input.
      Returns:
      the serialized output.
    • deserialize

      public <T> T deserialize(Class<T> target, byte[] input)
      Description copied from interface: JsonSerializer
      Deserializes raw input into the target class.
      Specified by:
      deserialize in interface JsonSerializer
      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: JsonSerializer
      Deserializes raw input into the target type.
      Specified by:
      deserialize in interface JsonSerializer
      Type Parameters:
      T - the type to deserialize into.
      Parameters:
      target - the target type.
      input - the raw input.
      Returns:
      the deserialized output.