Class JsonSerde<T>

java.lang.Object
org.springframework.kafka.support.serializer.JsonSerde<T>
Type Parameters:
T - target class for serialization/deserialization
All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.kafka.common.serialization.Serde<T>

public class JsonSerde<T> extends 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 Details

    • JsonSerde

      public JsonSerde()
    • JsonSerde

      public JsonSerde(@Nullable 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 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)
    • JsonSerde

      public JsonSerde(JsonSerializer<T> jsonSerializer, JsonDeserializer<T> jsonDeserializer)
  • Method Details

    • configure

      public void configure(Map<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 AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface org.apache.kafka.common.serialization.Serde<T>
    • serializer

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

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

      public <X> JsonSerde<X> copyWithType(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
    • typeMapper

      public JsonSerde<T> typeMapper(Jackson2JavaTypeMapper mapper)
      Use the supplied Jackson2JavaTypeMapper.
      Parameters:
      mapper - the mapper.
      Returns:
      the serde.
      Since:
      2.3