Class DelegatingSerializer
java.lang.Object
org.springframework.kafka.support.serializer.DelegatingSerializer
- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.apache.kafka.common.serialization.Serializer<Object>
public class DelegatingSerializer
extends Object
implements org.apache.kafka.common.serialization.Serializer<Object>
A
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.- Since:
- 2.3
- Author:
- Gary Russell
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Name of the header containing the serialization selector for keys.static final String
Name of the configuration property containing the serialization selector map for keys with formatselector:class,...
.static final String
Name of the header containing the serialization selector for values.static final String
Name of the configuration property containing the serialization selector map for values with formatselector:class,...
. -
Constructor Summary
ConstructorDescriptionConstruct an instance that will be configured inconfigure(Map, boolean)
with producer propertiesVALUE_SERIALIZATION_SELECTOR_CONFIG
andKEY_SERIALIZATION_SELECTOR_CONFIG
.DelegatingSerializer
(Map<String, org.apache.kafka.common.serialization.Serializer<?>> delegates) Construct an instance with the supplied mapping of selectors to delegate serializers. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDelegate
(String selector, org.apache.kafka.common.serialization.Serializer<?> serializer) void
close()
void
createDelegates
(String mappings, Map<String, ?> configs, boolean isKey) protected static void
createInstanceAndConfigure
(Map<String, ?> configs, boolean isKey, Map<String, org.apache.kafka.common.serialization.Serializer<?>> delegateMap, String selector, String className) protected static void
instantiateAndConfigure
(Map<String, ?> configs, boolean isKey, Map<String, org.apache.kafka.common.serialization.Serializer<?>> delegateMap, String selector, Class<?> clazz) org.apache.kafka.common.serialization.Serializer<?>
removeDelegate
(String selector) byte[]
byte[]
-
Field Details
-
VALUE_SERIALIZATION_SELECTOR
Name of the header containing the serialization selector for values.- See Also:
-
KEY_SERIALIZATION_SELECTOR
Name of the header containing the serialization selector for keys.- See Also:
-
VALUE_SERIALIZATION_SELECTOR_CONFIG
Name of the configuration property containing the serialization selector map for values with formatselector:class,...
.- See Also:
-
KEY_SERIALIZATION_SELECTOR_CONFIG
Name of the configuration property containing the serialization selector map for keys with formatselector:class,...
.- See Also:
-
-
Constructor Details
-
DelegatingSerializer
public DelegatingSerializer()Construct an instance that will be configured inconfigure(Map, boolean)
with producer propertiesVALUE_SERIALIZATION_SELECTOR_CONFIG
andKEY_SERIALIZATION_SELECTOR_CONFIG
. -
DelegatingSerializer
public DelegatingSerializer(Map<String, org.apache.kafka.common.serialization.Serializer<?>> delegates) Construct an instance with the supplied mapping of selectors to delegate serializers. The selector must be supplied in theKEY_SERIALIZATION_SELECTOR
and/orVALUE_SERIALIZATION_SELECTOR
headers. It is not necessary to configure standard serializers supported bySerdes
.- Parameters:
delegates
- the map of delegates.
-
-
Method Details
-
configure
- Specified by:
configure
in interfaceorg.apache.kafka.common.serialization.Serializer<Object>
-
createDelegates
-
createInstanceAndConfigure
-
instantiateAndConfigure
-
addDelegate
public void addDelegate(String selector, org.apache.kafka.common.serialization.Serializer<?> serializer) -
removeDelegate
-
serialize
- Specified by:
serialize
in interfaceorg.apache.kafka.common.serialization.Serializer<Object>
-
serialize
- Specified by:
serialize
in interfaceorg.apache.kafka.common.serialization.Serializer<Object>
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceorg.apache.kafka.common.serialization.Serializer<Object>
-