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 Summary
-
Constructor Summary
ConstructorDescriptionConstruct an instance with no parser function; a static method name must be provided in the consumer configKEY_PARSER
orVALUE_PARSER
properties.ParseStringDeserializer
(BiFunction<String, org.apache.kafka.common.header.Headers, T> parser) Construct an instance with the supplied parser function.ParseStringDeserializer
(Function<String, T> parser) Construct an instance with the supplied parser function. -
Method Summary
Modifier and TypeMethodDescriptionvoid
deserialize
(String topic, byte[] data) deserialize
(String topic, org.apache.kafka.common.header.Headers headers, byte[] data) deserialize
(String topic, org.apache.kafka.common.header.Headers headers, ByteBuffer data) Get the configured charset.BiFunction<String,
org.apache.kafka.common.header.Headers, T> Get the configured parser function.void
setCharset
(Charset charset) Set a charset to use when converting byte[] toString
.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 Details
-
KEY_PARSER
Property for the key parser method.- See Also:
-
VALUE_PARSER
Property for the key parser method.- See Also:
-
-
Constructor Details
-
ParseStringDeserializer
public ParseStringDeserializer()Construct an instance with no parser function; a static method name must be provided in the consumer configKEY_PARSER
orVALUE_PARSER
properties. -
ParseStringDeserializer
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
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
- Specified by:
configure
in interfaceorg.apache.kafka.common.serialization.Deserializer<T>
-
deserialize
- Specified by:
deserialize
in interfaceorg.apache.kafka.common.serialization.Deserializer<T>
-
deserialize
- Specified by:
deserialize
in interfaceorg.apache.kafka.common.serialization.Deserializer<T>
-
deserialize
- Specified by:
deserialize
in interfaceorg.apache.kafka.common.serialization.Deserializer<T>
-
setCharset
Set a charset to use when converting byte[] toString
. Default UTF-8.- Parameters:
charset
- the charset.
-
getCharset
Get the configured charset.- Returns:
- the charset.
-
getParser
Get the configured parser function.- Returns:
- the function.
-