T
- class of the entity, representing messagespublic class JsonSerializer<T>
extends java.lang.Object
implements org.apache.kafka.common.serialization.ExtendedSerializer<T>
Serializer
for sending Java objects to Kafka as JSON.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ADD_TYPE_INFO_HEADERS
Kafka config property for to disable adding type headers.
|
protected boolean |
addTypeInfo |
protected com.fasterxml.jackson.databind.ObjectMapper |
objectMapper |
protected Jackson2JavaTypeMapper |
typeMapper |
Constructor and Description |
---|
JsonSerializer() |
JsonSerializer(com.fasterxml.jackson.databind.ObjectMapper objectMapper) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
configure(java.util.Map<java.lang.String,?> configs,
boolean isKey) |
Jackson2JavaTypeMapper |
getTypeMapper() |
boolean |
isAddTypeInfo() |
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 |
setTypeMapper(Jackson2JavaTypeMapper typeMapper)
Set a customized type mapper.
|
public static final java.lang.String ADD_TYPE_INFO_HEADERS
protected final com.fasterxml.jackson.databind.ObjectMapper objectMapper
protected boolean addTypeInfo
protected Jackson2JavaTypeMapper typeMapper
public JsonSerializer()
public JsonSerializer(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
public boolean isAddTypeInfo()
public void setAddTypeInfo(boolean addTypeInfo)
addTypeInfo
- true to add headers.public Jackson2JavaTypeMapper getTypeMapper()
public void setTypeMapper(Jackson2JavaTypeMapper typeMapper)
typeMapper
- the type mapper.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, org.apache.kafka.common.header.Headers headers, T data)
serialize
in interface org.apache.kafka.common.serialization.ExtendedSerializer<T>
public byte[] serialize(java.lang.String topic, 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>