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:
Closeable
,AutoCloseable
,org.apache.kafka.common.serialization.Deserializer<T>
public class ErrorHandlingDeserializer<T>
extends 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
Modifier and TypeFieldDescriptionstatic final String
Property name for the delegate key deserializer.static final String
Supplier for a T when deserialization fails.static final String
Property name for the validator.static final String
Property name for the delegate value deserializer.static final String
Supplier for a T when deserialization fails. -
Constructor Summary
ConstructorDescriptionErrorHandlingDeserializer
(org.apache.kafka.common.serialization.Deserializer<T> delegate) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
deserialize
(String topic, byte[] data) deserialize
(String topic, org.apache.kafka.common.header.Headers headers, byte[] data) boolean
isForKey()
keyDeserializer
(boolean isKey) Set to true if this deserializer is to be used as a key deserializer when configuring outside of Kafka.void
setFailedDeserializationFunction
(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
(Map<String, ?> configs, String configKey) void
setValidator
(Validator validator) Set a validator to validate the object after successful deserialization.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
deserialize
-
Field Details
-
KEY_FUNCTION
Supplier for a T when deserialization fails.- See Also:
-
VALUE_FUNCTION
Supplier for a T when deserialization fails.- See Also:
-
KEY_DESERIALIZER_CLASS
Property name for the delegate key deserializer.- See Also:
-
VALUE_DESERIALIZER_CLASS
Property name for the delegate value deserializer.- See Also:
-
VALIDATOR_CLASS
Property name for the validator.- See Also:
-
-
Constructor Details
-
ErrorHandlingDeserializer
public ErrorHandlingDeserializer() -
ErrorHandlingDeserializer
-
-
Method Details
-
setFailedDeserializationFunction
public void setFailedDeserializationFunction(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
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
-
setValidator
Set a validator to validate the object after successful deserialization. If the validator throws an exception, or returns anErrors
with validation failures, the raw data will be available in any configured error handler.- Parameters:
validator
- the validator to set- Since:
- 3.1
-
configure
- Specified by:
configure
in interfaceorg.apache.kafka.common.serialization.Deserializer<T>
-
setupDelegate
-
deserialize
- Specified by:
deserialize
in interfaceorg.apache.kafka.common.serialization.Deserializer<T>
-
deserialize
- Specified by:
deserialize
in interfaceorg.apache.kafka.common.serialization.Deserializer<T>
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceorg.apache.kafka.common.serialization.Deserializer<T>
-