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 Details

    • VALUE_SERIALIZATION_SELECTOR

      public static final String VALUE_SERIALIZATION_SELECTOR
      Name of the header containing the serialization selector for values.
      See Also:
    • KEY_SERIALIZATION_SELECTOR

      public static final String KEY_SERIALIZATION_SELECTOR
      Name of the header containing the serialization selector for keys.
      See Also:
    • VALUE_SERIALIZATION_SELECTOR_CONFIG

      public static final String VALUE_SERIALIZATION_SELECTOR_CONFIG
      Name of the configuration property containing the serialization selector map for values with format selector:class,....
      See Also:
    • KEY_SERIALIZATION_SELECTOR_CONFIG

      public static final String KEY_SERIALIZATION_SELECTOR_CONFIG
      Name of the configuration property containing the serialization selector map for keys with format selector:class,....
      See Also:
  • Constructor Details

  • Method Details

    • configure

      public void configure(Map<String,?> configs, boolean isKey)
      Specified by:
      configure in interface org.apache.kafka.common.serialization.Serializer<Object>
    • createDelegates

      protected static Map<String,org.apache.kafka.common.serialization.Serializer<?>> createDelegates(String mappings, Map<String,?> configs, boolean isKey)
    • createInstanceAndConfigure

      protected static void createInstanceAndConfigure(Map<String,?> configs, boolean isKey, Map<String,org.apache.kafka.common.serialization.Serializer<?>> delegateMap, String selector, String className)
    • instantiateAndConfigure

      protected static void instantiateAndConfigure(Map<String,?> configs, boolean isKey, Map<String,org.apache.kafka.common.serialization.Serializer<?>> delegateMap, String selector, Class<?> clazz)
    • addDelegate

      public void addDelegate(String selector, org.apache.kafka.common.serialization.Serializer<?> serializer)
    • removeDelegate

      @Nullable public org.apache.kafka.common.serialization.Serializer<?> removeDelegate(String selector)
    • serialize

      public byte[] serialize(String topic, Object data)
      Specified by:
      serialize in interface org.apache.kafka.common.serialization.Serializer<Object>
    • serialize

      public byte[] serialize(String topic, org.apache.kafka.common.header.Headers headers, Object data)
      Specified by:
      serialize in interface org.apache.kafka.common.serialization.Serializer<Object>
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface org.apache.kafka.common.serialization.Serializer<Object>