Class DelegatingSerializer

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, org.apache.kafka.common.serialization.Serializer<java.lang.Object>

    public class DelegatingSerializer
    extends java.lang.Object
    implements org.apache.kafka.common.serialization.Serializer<java.lang.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

      Fields 
      Modifier and Type Field 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 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,....
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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, java.lang.Object data)  
      byte[] serialize​(java.lang.String topic, org.apache.kafka.common.header.Headers headers, java.lang.Object data)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • VALUE_SERIALIZATION_SELECTOR

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

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

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

        public static final java.lang.String KEY_SERIALIZATION_SELECTOR_CONFIG
        Name of the configuration property containing the serialization selector map for keys with format selector:class,....
        See Also:
        Constant Field Values
    • Method Detail

      • configure

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

        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)
      • createInstanceAndConfigure

        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)
      • instantiateAndConfigure

        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)
      • addDelegate

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

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

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

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

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