T
- class of the entity, representing messagespublic class ToStringSerializer<T>
extends java.lang.Object
implements org.apache.kafka.common.serialization.Serializer<T>
Serializer
that relies on
Object.toString()
to get serialized representation of the entity.Modifier and Type | Field and 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 and Description |
---|
ToStringSerializer() |
Modifier and Type | Method and 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 converting
String to byte[]. |
public static final java.lang.String ADD_TYPE_INFO_HEADERS
public static final java.lang.String KEY_TYPE
public static final java.lang.String VALUE_TYPE
public void configure(java.util.Map<java.lang.String,?> configs, boolean isKey)
configure
in interface org.apache.kafka.common.serialization.Serializer<T>
public byte[] serialize(java.lang.String topic, @Nullable T data)
serialize
in interface org.apache.kafka.common.serialization.Serializer<T>
@Nullable public byte[] serialize(java.lang.String topic, @Nullable org.apache.kafka.common.header.Headers headers, @Nullable T data)
serialize
in interface org.apache.kafka.common.serialization.Serializer<T>
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface org.apache.kafka.common.serialization.Serializer<T>
public boolean isAddTypeInfo()
public void setAddTypeInfo(boolean addTypeInfo)
addTypeInfo
- true to add headerspublic void setCharset(java.nio.charset.Charset charset)
String
to byte[]. Default UTF-8.charset
- the charset.public java.nio.charset.Charset getCharset()