Class ParseStringDeserializer<T>

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

public class ParseStringDeserializer<T> extends Object implements org.apache.kafka.common.serialization.Deserializer<T>
Generic Deserializer for deserialization of entity from its String representation received from Kafka (a.k.a parsing).
Since:
2.5
Author:
Alexei Klenin, Gary Russell, Wang Zhiyang
  • Field Details

  • Constructor Details

    • ParseStringDeserializer

      public ParseStringDeserializer()
      Construct an instance with no parser function; a static method name must be provided in the consumer config KEY_PARSER or VALUE_PARSER properties.
    • ParseStringDeserializer

      public ParseStringDeserializer(Function<String,T> parser)
      Construct an instance with the supplied parser function. The function may receive null as the input value, for example for a tombstone record in a compacted topic.
      Parameters:
      parser - the function.
    • ParseStringDeserializer

      public ParseStringDeserializer(BiFunction<String,org.apache.kafka.common.header.Headers,T> parser)
      Construct an instance with the supplied parser function. The function may receive null as the input value, for example for a tombstone record in a compacted topic.
      Parameters:
      parser - the function.
  • Method Details

    • configure

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

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

      public T deserialize(String topic, org.apache.kafka.common.header.Headers headers, byte[] data)
      Specified by:
      deserialize in interface org.apache.kafka.common.serialization.Deserializer<T>
    • deserialize

      public T deserialize(String topic, org.apache.kafka.common.header.Headers headers, ByteBuffer data)
      Specified by:
      deserialize in interface org.apache.kafka.common.serialization.Deserializer<T>
    • setCharset

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

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

      public BiFunction<String,org.apache.kafka.common.header.Headers,T> getParser()
      Get the configured parser function.
      Returns:
      the function.