Class ToStringSerializer<T>

java.lang.Object
org.springframework.kafka.support.serializer.ToStringSerializer<T>
Type Parameters:
T - class of the entity, representing messages
All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.kafka.common.serialization.Serializer<T>

public class ToStringSerializer<T> extends Object implements org.apache.kafka.common.serialization.Serializer<T>
Generic Serializer that relies on Object.toString() to get serialized representation of the entity.
Since:
2.5
Author:
Alexei Klenin, Gary Russell
  • Field Details

  • Constructor Details

    • ToStringSerializer

      public ToStringSerializer()
  • Method Details

    • configure

      public void configure(Map<String,?> configs, boolean isKey)
      Specified by:
      configure in interface org.apache.kafka.common.serialization.Serializer<T>
    • serialize

      public byte[] serialize(String topic, @Nullable T data)
      Specified by:
      serialize in interface org.apache.kafka.common.serialization.Serializer<T>
    • serialize

      @Nullable public byte[] serialize(String topic, @Nullable org.apache.kafka.common.header.Headers headers, @Nullable T data)
      Specified by:
      serialize in interface org.apache.kafka.common.serialization.Serializer<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.Serializer<T>
    • isAddTypeInfo

      public boolean isAddTypeInfo()
      Get the addTypeInfo property.
      Returns:
      the addTypeInfo
    • setAddTypeInfo

      public void setAddTypeInfo(boolean addTypeInfo)
      Set to false to disable adding type info headers.
      Parameters:
      addTypeInfo - true to add headers
    • setCharset

      public void setCharset(Charset charset)
      Set a charset to use when converting String to byte[]. Default UTF-8.
      Parameters:
      charset - the charset.
    • getCharset

      public Charset getCharset()
      Get the configured charset.
      Returns:
      the charset.