Class JacksonJsonSerializer

  • All Implemented Interfaces:
    JsonSerializer

    public class JacksonJsonSerializer
    extends Object
    implements 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 if desired.

    Example usage:

     ObjectMapper mapper = new ObjectMapper();
     mapper.registerModule(new JsonValueModule());
    
     ClusterEnvironment env = ClusterEnvironment.builder()
         .jsonSerializer(new JacksonJsonSerializer(mapper))
         .build();
     

    See Also:
    JsonValueModule
    • 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.
      • 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.