Class ParseStringDeserializer<T>

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

    public class ParseStringDeserializer<T>
    extends java.lang.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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String KEY_PARSER
      Property for the key parser method.
      static java.lang.String VALUE_PARSER
      Property for the key parser method.
    • Constructor Summary

      Constructors 
      Constructor Description
      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​(java.util.function.BiFunction<java.lang.String,​org.apache.kafka.common.header.Headers,​T> parser)
      Construct an instance with the supplied parser function.
      ParseStringDeserializer​(java.util.function.Function<java.lang.String,​T> parser)
      Construct an instance with the supplied parser function.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void configure​(java.util.Map<java.lang.String,​?> configs, boolean isKey)  
      T deserialize​(java.lang.String topic, byte[] data)  
      T deserialize​(java.lang.String topic, org.apache.kafka.common.header.Headers headers, byte[] data)  
      java.nio.charset.Charset getCharset()
      Get the configured charset.
      java.util.function.BiFunction<java.lang.String,​org.apache.kafka.common.header.Headers,​T> getParser()
      Get the configured parser function.
      void setCharset​(java.nio.charset.Charset charset)
      Set a charset to use when converting byte[] to String.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.apache.kafka.common.serialization.Deserializer

        close
    • Field Detail

      • KEY_PARSER

        public static final java.lang.String KEY_PARSER
        Property for the key parser method.
        See Also:
        Constant Field Values
      • VALUE_PARSER

        public static final java.lang.String VALUE_PARSER
        Property for the key parser method.
        See Also:
        Constant Field Values
    • Constructor Detail

      • 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​(java.util.function.Function<java.lang.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​(java.util.function.BiFunction<java.lang.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 Detail

      • configure

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

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

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

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

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

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