public class DelegatingSerializer
extends java.lang.Object
implements org.apache.kafka.common.serialization.Serializer<java.lang.Object>
Serializer
that delegates to other serializers based on a serialization
selector header. If the header is missing, and the type is supported by Serdes
we will delegate to that serializer type.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
KEY_SERIALIZATION_SELECTOR
Name of the header containing the serialization selector for keys.
|
static java.lang.String |
KEY_SERIALIZATION_SELECTOR_CONFIG
Name of the configuration property containing the serialization selector map for
keys with format
selector:class,... . |
static java.lang.String |
SERIALIZATION_SELECTOR
Deprecated.
in favor of
VALUE_SERIALIZATION_SELECTOR . |
static java.lang.String |
SERIALIZATION_SELECTOR_CONFIG
Deprecated.
in favor of
VALUE_SERIALIZATION_SELECTOR_CONFIG . |
static java.lang.String |
VALUE_SERIALIZATION_SELECTOR
Name of the header containing the serialization selector for values.
|
static java.lang.String |
VALUE_SERIALIZATION_SELECTOR_CONFIG
Name of the configuration property containing the serialization selector map for
values with format
selector:class,... . |
Constructor and Description |
---|
DelegatingSerializer()
Construct an instance that will be configured in
configure(Map, boolean)
with producer properties VALUE_SERIALIZATION_SELECTOR_CONFIG and
KEY_SERIALIZATION_SELECTOR_CONFIG . |
DelegatingSerializer(java.util.Map<java.lang.String,org.apache.kafka.common.serialization.Serializer<?>> delegates)
Construct an instance with the supplied mapping of selectors to delegate
serializers.
|
Modifier and Type | Method and Description |
---|---|
void |
addDelegate(java.lang.String selector,
org.apache.kafka.common.serialization.Serializer<?> serializer) |
void |
close() |
void |
configure(java.util.Map<java.lang.String,?> configs,
boolean isKey) |
protected static java.util.Map<java.lang.String,org.apache.kafka.common.serialization.Serializer<?>> |
createDelegates(java.lang.String mappings,
java.util.Map<java.lang.String,?> configs,
boolean isKey) |
protected static void |
createInstanceAndConfigure(java.util.Map<java.lang.String,?> configs,
boolean isKey,
java.util.Map<java.lang.String,org.apache.kafka.common.serialization.Serializer<?>> delegateMap,
java.lang.String selector,
java.lang.String className) |
protected static void |
instantiateAndConfigure(java.util.Map<java.lang.String,?> configs,
boolean isKey,
java.util.Map<java.lang.String,org.apache.kafka.common.serialization.Serializer<?>> delegateMap,
java.lang.String selector,
java.lang.Class<?> clazz) |
org.apache.kafka.common.serialization.Serializer<?> |
removeDelegate(java.lang.String selector) |
byte[] |
serialize(java.lang.String topic,
org.apache.kafka.common.header.Headers headers,
java.lang.Object data) |
byte[] |
serialize(java.lang.String topic,
java.lang.Object data) |
@Deprecated public static final java.lang.String SERIALIZATION_SELECTOR
VALUE_SERIALIZATION_SELECTOR
.VALUE_SERIALIZATION_SELECTOR
.public static final java.lang.String VALUE_SERIALIZATION_SELECTOR
public static final java.lang.String KEY_SERIALIZATION_SELECTOR
@Deprecated public static final java.lang.String SERIALIZATION_SELECTOR_CONFIG
VALUE_SERIALIZATION_SELECTOR_CONFIG
.VALUE_SERIALIZATION_SELECTOR_CONFIG
.public static final java.lang.String VALUE_SERIALIZATION_SELECTOR_CONFIG
selector:class,...
.public static final java.lang.String KEY_SERIALIZATION_SELECTOR_CONFIG
selector:class,...
.public DelegatingSerializer()
configure(Map, boolean)
with producer properties VALUE_SERIALIZATION_SELECTOR_CONFIG
and
KEY_SERIALIZATION_SELECTOR_CONFIG
.public DelegatingSerializer(java.util.Map<java.lang.String,org.apache.kafka.common.serialization.Serializer<?>> delegates)
KEY_SERIALIZATION_SELECTOR
and/or VALUE_SERIALIZATION_SELECTOR
headers. It is not necessary to configure standard serializers supported by
Serdes
.delegates
- the map of delegates.public void configure(java.util.Map<java.lang.String,?> configs, boolean isKey)
configure
in interface org.apache.kafka.common.serialization.Serializer<java.lang.Object>
protected static java.util.Map<java.lang.String,org.apache.kafka.common.serialization.Serializer<?>> createDelegates(java.lang.String mappings, java.util.Map<java.lang.String,?> configs, boolean isKey)
protected static void createInstanceAndConfigure(java.util.Map<java.lang.String,?> configs, boolean isKey, java.util.Map<java.lang.String,org.apache.kafka.common.serialization.Serializer<?>> delegateMap, java.lang.String selector, java.lang.String className)
protected static void instantiateAndConfigure(java.util.Map<java.lang.String,?> configs, boolean isKey, java.util.Map<java.lang.String,org.apache.kafka.common.serialization.Serializer<?>> delegateMap, java.lang.String selector, java.lang.Class<?> clazz)
public void addDelegate(java.lang.String selector, org.apache.kafka.common.serialization.Serializer<?> serializer)
@Nullable public org.apache.kafka.common.serialization.Serializer<?> removeDelegate(java.lang.String selector)
public byte[] serialize(java.lang.String topic, java.lang.Object data)
serialize
in interface org.apache.kafka.common.serialization.Serializer<java.lang.Object>
public byte[] serialize(java.lang.String topic, org.apache.kafka.common.header.Headers headers, java.lang.Object data)
serialize
in interface org.apache.kafka.common.serialization.Serializer<java.lang.Object>
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface org.apache.kafka.common.serialization.Serializer<java.lang.Object>