Class ToStringSerializer<T>
java.lang.Object
org.springframework.kafka.support.serializer.ToStringSerializer<T>
- Type Parameters:
T- class of the entity, representing messages
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.kafka.common.serialization.Serializer<T>
public class ToStringSerializer<T>
extends Object
implements org.apache.kafka.common.serialization.Serializer<T>
Generic
Serializer that relies on
Object.toString() to get serialized representation of the entity.- Since:
- 2.5
- Author:
- Alexei Klenin, Gary Russell
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidGet the configured charset.booleanGet the addTypeInfo property.byte[]byte[]voidsetAddTypeInfo(boolean addTypeInfo) Set to false to disable adding type info headers.voidsetCharset(Charset charset) Set a charset to use when convertingStringto byte[].
-
Field Details
-
ADD_TYPE_INFO_HEADERS
Kafka config property for enabling/disabling adding type headers.- See Also:
-
KEY_TYPE
Header for the type of key.- See Also:
-
VALUE_TYPE
Header for the type of value.- See Also:
-
-
Constructor Details
-
ToStringSerializer
public ToStringSerializer()
-
-
Method Details
-
configure
- Specified by:
configurein interfaceorg.apache.kafka.common.serialization.Serializer<T>
-
serialize
- Specified by:
serializein interfaceorg.apache.kafka.common.serialization.Serializer<T>
-
serialize
@Nullable public byte[] serialize(String topic, @Nullable org.apache.kafka.common.header.Headers headers, @Nullable T data) - Specified by:
serializein interfaceorg.apache.kafka.common.serialization.Serializer<T>
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceorg.apache.kafka.common.serialization.Serializer<T>
-
isAddTypeInfo
public boolean isAddTypeInfo()Get the addTypeInfo property.- Returns:
- the addTypeInfo
-
setAddTypeInfo
public void setAddTypeInfo(boolean addTypeInfo) Set to false to disable adding type info headers.- Parameters:
addTypeInfo- true to add headers
-
setCharset
Set a charset to use when convertingStringto byte[]. Default UTF-8.- Parameters:
charset- the charset.
-
getCharset
Get the configured charset.- Returns:
- the charset.
-