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:
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>
GenericDeserializer
for deserialization of entity from itsString
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 configKEY_PARSER
orVALUE_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[] toString
.
-
-
-
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 configKEY_PARSER
orVALUE_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 interfaceorg.apache.kafka.common.serialization.Deserializer<T>
-
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>
-
setCharset
public void setCharset(java.nio.charset.Charset charset)
Set a charset to use when converting byte[] toString
. 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.
-
-