Class ErrorHandlingDeserializer<T>
- java.lang.Object
-
- org.springframework.kafka.support.serializer.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
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
KEY_DESERIALIZER_CLASS
Property name for the delegate key deserializer.static java.lang.String
KEY_DESERIALIZER_EXCEPTION_HEADER
Deprecated.in favor ofSerializationUtils.KEY_DESERIALIZER_EXCEPTION_HEADER
.static java.lang.String
KEY_DESERIALIZER_EXCEPTION_HEADER_PREFIX
Deprecated.static java.lang.String
KEY_FUNCTION
Supplier for a T when deserialization fails.static java.lang.String
VALUE_DESERIALIZER_CLASS
Property name for the delegate value deserializer.static java.lang.String
VALUE_DESERIALIZER_EXCEPTION_HEADER
Deprecated.static java.lang.String
VALUE_FUNCTION
Supplier for a T when deserialization fails.
-
Constructor Summary
Constructors Constructor Description ErrorHandlingDeserializer()
ErrorHandlingDeserializer(org.apache.kafka.common.serialization.Deserializer<T> delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
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)
boolean
isForKey()
ErrorHandlingDeserializer<T>
keyDeserializer(boolean isKey)
Set to true if this deserializer is to be used as a key deserializer when configuring outside of Kafka.void
setFailedDeserializationFunction(java.util.function.Function<FailedDeserializationInfo,T> failedDeserializationFunction)
Provide an alternative supplying mechanism when deserialization fails.void
setForKey(boolean isKey)
Set to true if this deserializer is to be used as a key deserializer when configuring outside of Kafka.void
setupDelegate(java.util.Map<java.lang.String,?> configs, java.lang.String configKey)
-
-
-
Field Detail
-
KEY_DESERIALIZER_EXCEPTION_HEADER_PREFIX
@Deprecated public static final java.lang.String KEY_DESERIALIZER_EXCEPTION_HEADER_PREFIX
Deprecated.Header name for deserialization exceptions.- See Also:
- Constant Field Values
-
KEY_DESERIALIZER_EXCEPTION_HEADER
@Deprecated public static final java.lang.String KEY_DESERIALIZER_EXCEPTION_HEADER
Deprecated.in favor ofSerializationUtils.KEY_DESERIALIZER_EXCEPTION_HEADER
.Header name for deserialization exceptions.- See Also:
- Constant Field Values
-
VALUE_DESERIALIZER_EXCEPTION_HEADER
@Deprecated public static final java.lang.String VALUE_DESERIALIZER_EXCEPTION_HEADER
Deprecated.Header name for deserialization exceptions.- See Also:
- Constant Field Values
-
KEY_FUNCTION
public static final java.lang.String KEY_FUNCTION
Supplier for a T when deserialization fails.- See Also:
- Constant Field Values
-
VALUE_FUNCTION
public static final java.lang.String VALUE_FUNCTION
Supplier for a T when deserialization fails.- See Also:
- Constant Field Values
-
KEY_DESERIALIZER_CLASS
public static final java.lang.String KEY_DESERIALIZER_CLASS
Property name for the delegate key deserializer.- See Also:
- Constant Field Values
-
VALUE_DESERIALIZER_CLASS
public static final java.lang.String VALUE_DESERIALIZER_CLASS
Property name for the delegate value deserializer.- See Also:
- Constant Field Values
-
-
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
- theFunction
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 interfaceorg.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 interfaceorg.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 interfaceorg.apache.kafka.common.serialization.Deserializer<T>
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceorg.apache.kafka.common.serialization.Deserializer<T>
-
-