Class JsonSerde<T>

  • Type Parameters:
    T - target class for serialization/deserialization
    All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, org.apache.kafka.common.serialization.Serde<T>

    public class JsonSerde<T>
    extends java.lang.Object
    implements org.apache.kafka.common.serialization.Serde<T>
    A Serde that provides serialization and deserialization in JSON format.

    The implementation delegates to underlying JsonSerializer and JsonDeserializer implementations.

    Since:
    1.1.5
    Author:
    Marius Bogoevici, Elliot Kennedy, Gary Russell, Ivan Ponomarev
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonSerde()  
      JsonSerde​(com.fasterxml.jackson.core.type.TypeReference<? super T> targetType)  
      JsonSerde​(com.fasterxml.jackson.core.type.TypeReference<? super T> targetType, com.fasterxml.jackson.databind.ObjectMapper objectMapper)  
      JsonSerde​(com.fasterxml.jackson.databind.JavaType targetType)  
      JsonSerde​(com.fasterxml.jackson.databind.JavaType targetTypeArg, com.fasterxml.jackson.databind.ObjectMapper objectMapperArg)  
      JsonSerde​(com.fasterxml.jackson.databind.ObjectMapper objectMapper)  
      JsonSerde​(java.lang.Class<? super T> targetType)  
      JsonSerde​(java.lang.Class<? super T> targetType, com.fasterxml.jackson.databind.ObjectMapper objectMapper)  
      JsonSerde​(JsonSerializer<T> jsonSerializer, JsonDeserializer<T> jsonDeserializer)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void configure​(java.util.Map<java.lang.String,​?> configs, boolean isKey)  
      <X> JsonSerde<X> copyWithType​(com.fasterxml.jackson.core.type.TypeReference<? super X> newTargetType)
      Copies this serde with same configuration, except new target type reference is used.
      <X> JsonSerde<X> copyWithType​(com.fasterxml.jackson.databind.JavaType newTargetType)
      Copies this serde with same configuration, except new target java type is used.
      <X> JsonSerde<X> copyWithType​(java.lang.Class<? super X> newTargetType)
      Copies this serde with same configuration, except new target type is used.
      org.apache.kafka.common.serialization.Deserializer<T> deserializer()  
      JsonSerde<T> dontRemoveTypeHeaders()
      Don't remove type information headers after deserialization.
      JsonSerde<T> forKeys()
      Designate this Serde for serializing/deserializing keys (default is values).
      JsonSerde<T> ignoreTypeHeaders()
      Ignore type information headers and use the configured target class.
      JsonSerde<T> noTypeInfo()
      Configure the serializer to not add type information.
      org.apache.kafka.common.serialization.Serializer<T> serializer()  
      JsonSerde<T> typeMapper​(Jackson2JavaTypeMapper mapper)
      Use the supplied Jackson2JavaTypeMapper.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JsonSerde

        public JsonSerde()
      • JsonSerde

        public JsonSerde​(@Nullable
                         java.lang.Class<? super T> targetType)
      • JsonSerde

        public JsonSerde​(@Nullable
                         com.fasterxml.jackson.core.type.TypeReference<? super T> targetType)
      • JsonSerde

        public JsonSerde​(@Nullable
                         com.fasterxml.jackson.databind.JavaType targetType)
      • JsonSerde

        public JsonSerde​(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      • JsonSerde

        public JsonSerde​(@Nullable
                         com.fasterxml.jackson.core.type.TypeReference<? super T> targetType,
                         com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      • JsonSerde

        public JsonSerde​(@Nullable
                         java.lang.Class<? super T> targetType,
                         com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      • JsonSerde

        public JsonSerde​(@Nullable
                         com.fasterxml.jackson.databind.JavaType targetTypeArg,
                         @Nullable
                         com.fasterxml.jackson.databind.ObjectMapper objectMapperArg)
    • Method Detail

      • configure

        public void configure​(java.util.Map<java.lang.String,​?> configs,
                              boolean isKey)
        Specified by:
        configure in interface org.apache.kafka.common.serialization.Serde<T>
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface org.apache.kafka.common.serialization.Serde<T>
      • serializer

        public org.apache.kafka.common.serialization.Serializer<T> serializer()
        Specified by:
        serializer in interface org.apache.kafka.common.serialization.Serde<T>
      • deserializer

        public org.apache.kafka.common.serialization.Deserializer<T> deserializer()
        Specified by:
        deserializer in interface org.apache.kafka.common.serialization.Serde<T>
      • copyWithType

        public <X> JsonSerde<X> copyWithType​(java.lang.Class<? super X> newTargetType)
        Copies this serde with same configuration, except new target type is used.
        Type Parameters:
        X - new deserialization result type and serialization source type
        Parameters:
        newTargetType - type reference forced for serialization, and used as default for deserialization, not null
        Returns:
        new instance of serde with type changes
        Since:
        2.6
      • copyWithType

        public <X> JsonSerde<X> copyWithType​(com.fasterxml.jackson.core.type.TypeReference<? super X> newTargetType)
        Copies this serde with same configuration, except new target type reference is used.
        Type Parameters:
        X - new deserialization result type and serialization source type
        Parameters:
        newTargetType - type reference forced for serialization, and used as default for deserialization, not null
        Returns:
        new instance of serde with type changes
        Since:
        2.6
      • copyWithType

        public <X> JsonSerde<X> copyWithType​(com.fasterxml.jackson.databind.JavaType newTargetType)
        Copies this serde with same configuration, except new target java type is used.
        Type Parameters:
        X - new deserialization result type and serialization source type
        Parameters:
        newTargetType - java type forced for serialization, and used as default for deserialization, not null
        Returns:
        new instance of serde with type changes
        Since:
        2.6
      • forKeys

        public JsonSerde<T> forKeys()
        Designate this Serde for serializing/deserializing keys (default is values).
        Returns:
        the serde.
        Since:
        2.3
      • noTypeInfo

        public JsonSerde<T> noTypeInfo()
        Configure the serializer to not add type information.
        Returns:
        the serde.
        Since:
        2.3
      • dontRemoveTypeHeaders

        public JsonSerde<T> dontRemoveTypeHeaders()
        Don't remove type information headers after deserialization.
        Returns:
        the serde.
        Since:
        2.3
      • ignoreTypeHeaders

        public JsonSerde<T> ignoreTypeHeaders()
        Ignore type information headers and use the configured target class.
        Returns:
        the serde.
        Since:
        2.3