Class ErrorHandlingDeserializer<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 ErrorHandlingDeserializer<T>
    extends java.lang.Object
    implements org.apache.kafka.common.serialization.Deserializer<T>
    Delegating key/value deserializer that catches exceptions, returning them in the headers as serialized java objects.
    Since:
    2.2
    Author:
    Gary Russell, Artem Bilan, Victor Perez Rey
    • Constructor Detail

      • ErrorHandlingDeserializer

        public ErrorHandlingDeserializer()
      • ErrorHandlingDeserializer

        public ErrorHandlingDeserializer​(org.apache.kafka.common.serialization.Deserializer<T> delegate)
    • Method Detail

      • setFailedDeserializationFunction

        public void setFailedDeserializationFunction​(java.util.function.Function<FailedDeserializationInfo,​T> failedDeserializationFunction)
        Provide an alternative supplying mechanism when deserialization fails.
        Parameters:
        failedDeserializationFunction - the Function to use.
        Since:
        2.2.8
      • isForKey

        public boolean isForKey()
      • setForKey

        public void setForKey​(boolean isKey)
        Set to true if this deserializer is to be used as a key deserializer when configuring outside of Kafka.
        Parameters:
        isKey - true for a key deserializer, false otherwise.
        Since:
        2.2.3
      • keyDeserializer

        public ErrorHandlingDeserializer<T> keyDeserializer​(boolean isKey)
        Set to true if this deserializer is to be used as a key deserializer when configuring outside of Kafka.
        Parameters:
        isKey - true for a key deserializer, false otherwise.
        Returns:
        this
        Since:
        2.2.3
      • 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>
      • setupDelegate

        public void setupDelegate​(java.util.Map<java.lang.String,​?> configs,
                                  java.lang.String configKey)
      • 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>
      • 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.Deserializer<T>