Class SerializationUtils


  • public final class SerializationUtils
    extends java.lang.Object
    Utilities for serialization.
    Since:
    2.5
    Author:
    Gary Russell
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void deserializationException​(org.apache.kafka.common.header.Headers headers, byte[] data, java.lang.Exception ex, boolean isForKeyArg)
      Populate the record headers with a serialized DeserializationException.
      static <P,​T>
      java.util.function.BiFunction<P,​org.apache.kafka.common.header.Headers,​T>
      propertyToMethodInvokingFunction​(java.lang.String methodProperty, java.lang.Class<P> payloadType, java.lang.ClassLoader classLoader)
      Convert a property value (FQCN.methodName) to a BiFunction that takes a payload and headers and returns some value.
      • Methods inherited from class java.lang.Object

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

      • DESERIALIZER_EXCEPTION_HEADER_PREFIX

        public static final java.lang.String DESERIALIZER_EXCEPTION_HEADER_PREFIX
        Header name for deserialization exceptions.
        Since:
        2.8
        See Also:
        Constant Field Values
      • KEY_DESERIALIZER_EXCEPTION_HEADER

        public static final java.lang.String KEY_DESERIALIZER_EXCEPTION_HEADER
        Header name for deserialization exceptions.
        Since:
        2.8
        See Also:
        Constant Field Values
      • VALUE_DESERIALIZER_EXCEPTION_HEADER

        public static final java.lang.String VALUE_DESERIALIZER_EXCEPTION_HEADER
        Header name for deserialization exceptions.
        Since:
        2.8
        See Also:
        Constant Field Values
    • Method Detail

      • propertyToMethodInvokingFunction

        public static <P,​T> java.util.function.BiFunction<P,​org.apache.kafka.common.header.Headers,​T> propertyToMethodInvokingFunction​(java.lang.String methodProperty,
                                                                                                                                                         java.lang.Class<P> payloadType,
                                                                                                                                                         java.lang.ClassLoader classLoader)
        Convert a property value (FQCN.methodName) to a BiFunction that takes a payload and headers and returns some value. The method must have parameters (P, Headers) or (P) and be declared as static.
        Type Parameters:
        P - The BiFunction first parameter type.
        T - The BiFunction return type.
        Parameters:
        methodProperty - the method name property.
        payloadType - the BiFunction first parameter type.
        classLoader - the class loader.
        Returns:
        the function.
      • deserializationException

        public static void deserializationException​(org.apache.kafka.common.header.Headers headers,
                                                    byte[] data,
                                                    java.lang.Exception ex,
                                                    boolean isForKeyArg)
        Populate the record headers with a serialized DeserializationException.
        Parameters:
        headers - the headers.
        data - the data.
        ex - the exception.
        isForKeyArg - true if this is a key deserialization problem, otherwise value.
        Since:
        2.8