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>GenericDeserializerfor deserialization of entity from itsStringrepresentation 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.StringKEY_PARSERProperty for the key parser method.static java.lang.StringVALUE_PARSERProperty 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_PARSERorVALUE_PARSERproperties.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 voidconfigure(java.util.Map<java.lang.String,?> configs, boolean isKey)Tdeserialize(java.lang.String topic, byte[] data)Tdeserialize(java.lang.String topic, org.apache.kafka.common.header.Headers headers, byte[] data)java.nio.charset.CharsetgetCharset()Get the configured charset.java.util.function.BiFunction<java.lang.String,org.apache.kafka.common.header.Headers,T>getParser()Get the configured parser function.voidsetCharset(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_PARSERorVALUE_PARSERproperties.
-
ParseStringDeserializer
public ParseStringDeserializer(java.util.function.Function<java.lang.String,T> parser)
Construct an instance with the supplied parser function.- 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.- Parameters:
parser- the function.
-
-
Method Detail
-
configure
public void configure(java.util.Map<java.lang.String,?> configs, boolean isKey)- Specified by:
configurein interfaceorg.apache.kafka.common.serialization.Deserializer<T>
-
deserialize
public T deserialize(java.lang.String topic, byte[] data)
- Specified by:
deserializein 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:
deserializein 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.
-
-