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:
java.io.Closeable
,java.lang.AutoCloseable
,org.apache.kafka.common.serialization.Serializer<T>
public class ToStringSerializer<T> extends java.lang.Object implements org.apache.kafka.common.serialization.Serializer<T>
GenericSerializer
that relies onObject.toString()
to get serialized representation of the entity.- Since:
- 2.5
- Author:
- Alexei Klenin, Gary Russell
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ADD_TYPE_INFO_HEADERS
Kafka config property for enabling/disabling adding type headers.static java.lang.String
KEY_TYPE
Header for the type of key.static java.lang.String
VALUE_TYPE
Header for the type of value.
-
Constructor Summary
Constructors Constructor Description ToStringSerializer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
configure(java.util.Map<java.lang.String,?> configs, boolean isKey)
java.nio.charset.Charset
getCharset()
Get the configured charset.boolean
isAddTypeInfo()
Get the addTypeInfo property.byte[]
serialize(java.lang.String topic, org.apache.kafka.common.header.Headers headers, T data)
byte[]
serialize(java.lang.String topic, T data)
void
setAddTypeInfo(boolean addTypeInfo)
Set to false to disable adding type info headers.void
setCharset(java.nio.charset.Charset charset)
Set a charset to use when convertingString
to byte[].
-
-
-
Field Detail
-
ADD_TYPE_INFO_HEADERS
public static final java.lang.String ADD_TYPE_INFO_HEADERS
Kafka config property for enabling/disabling adding type headers.- See Also:
- Constant Field Values
-
KEY_TYPE
public static final java.lang.String KEY_TYPE
Header for the type of key.- See Also:
- Constant Field Values
-
VALUE_TYPE
public static final java.lang.String VALUE_TYPE
Header for the type of value.- See Also:
- Constant Field Values
-
-
Method Detail
-
configure
public void configure(java.util.Map<java.lang.String,?> configs, boolean isKey)
- Specified by:
configure
in interfaceorg.apache.kafka.common.serialization.Serializer<T>
-
serialize
public byte[] serialize(java.lang.String topic, @Nullable T data)
- Specified by:
serialize
in interfaceorg.apache.kafka.common.serialization.Serializer<T>
-
serialize
@Nullable public byte[] serialize(java.lang.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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- 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
public void setCharset(java.nio.charset.Charset charset)
Set a charset to use when convertingString
to byte[]. Default UTF-8.- Parameters:
charset
- the charset.
-
getCharset
public java.nio.charset.Charset getCharset()
Get the configured charset.- Returns:
- the charset.
-
-