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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
Get the configured charset.boolean
Get the addTypeInfo property.byte[]
byte[]
void
setAddTypeInfo
(boolean addTypeInfo) Set to false to disable adding type info headers.void
setCharset
(Charset charset) Set a charset to use when convertingString
to 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:
configure
in interfaceorg.apache.kafka.common.serialization.Serializer<T>
-
serialize
- Specified by:
serialize
in 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:
serialize
in interfaceorg.apache.kafka.common.serialization.Serializer<T>
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in 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 convertingString
to byte[]. Default UTF-8.- Parameters:
charset
- the charset.
-
getCharset
Get the configured charset.- Returns:
- the charset.
-