Class SerializationUtils
- java.lang.Object
-
- org.springframework.kafka.support.serializer.SerializationUtils
-
public final class SerializationUtils extends java.lang.ObjectUtilities for serialization.- Since:
- 2.5
- Author:
- Gary Russell
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDESERIALIZER_EXCEPTION_HEADER_PREFIXHeader name for deserialization exceptions.static java.lang.StringKEY_DESERIALIZER_EXCEPTION_HEADERHeader name for deserialization exceptions.static java.lang.StringVALUE_DESERIALIZER_EXCEPTION_HEADERHeader name for deserialization exceptions.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DeserializationExceptionbyteArrayToDeserializationException(org.springframework.core.log.LogAccessor logger, org.apache.kafka.common.header.Header header)Convert a byte array containing a serializedDeserializationExceptionto theDeserializationException.static voiddeserializationException(org.apache.kafka.common.header.Headers headers, byte[] data, java.lang.Exception ex, boolean isForKeyArg)Populate the record headers with a serializedDeserializationException.static DeserializationExceptiongetExceptionFromHeader(org.apache.kafka.clients.consumer.ConsumerRecord<?,?> record, java.lang.String headerName, org.springframework.core.log.LogAccessor logger)Extract aDeserializationExceptionfrom the supplied header name, if present.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 aBiFunctionthat takes a payload and headers and returns some value.
-
-
-
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 aBiFunctionthat 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- TheBiFunctionfirst parameter type.T- TheBiFunctionreturn type.- Parameters:
methodProperty- the method name property.payloadType- theBiFunctionfirst 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 serializedDeserializationException.- Parameters:
headers- the headers.data- the data.ex- the exception.isForKeyArg- true if this is a key deserialization problem, otherwise value.- Since:
- 2.8
-
getExceptionFromHeader
@Nullable public static DeserializationException getExceptionFromHeader(org.apache.kafka.clients.consumer.ConsumerRecord<?,?> record, java.lang.String headerName, org.springframework.core.log.LogAccessor logger)
Extract aDeserializationExceptionfrom the supplied header name, if present.- Parameters:
record- the consumer record.headerName- the header name.logger- the logger for logging errors.- Returns:
- the exception or null.
- Since:
- 2.9.11
-
byteArrayToDeserializationException
@Nullable public static DeserializationException byteArrayToDeserializationException(org.springframework.core.log.LogAccessor logger, org.apache.kafka.common.header.Header header)
Convert a byte array containing a serializedDeserializationExceptionto theDeserializationException.- Parameters:
logger- a log accessor to log errors.header- the header.- Returns:
- the exception or null if deserialization fails.
- Since:
- 2.9.11
-
-