Class DelegatingByTypeSerializer
- java.lang.Object
-
- org.springframework.kafka.support.serializer.DelegatingByTypeSerializer
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,org.apache.kafka.common.serialization.Serializer<java.lang.Object>
public class DelegatingByTypeSerializer extends java.lang.Object implements org.apache.kafka.common.serialization.Serializer<java.lang.Object>
Delegates to a serializer based on type.- Since:
- 2.7.9
-
-
Constructor Summary
Constructors Constructor Description DelegatingByTypeSerializer(java.util.Map<java.lang.Class<?>,org.apache.kafka.common.serialization.Serializer> delegates)
Construct an instance with the map of delegates; keys matched exactly.DelegatingByTypeSerializer(java.util.Map<java.lang.Class<?>,org.apache.kafka.common.serialization.Serializer> delegates, boolean assignable)
Construct an instance with the map of delegates; keys matched exactly or if the target object is assignable to the key, depending on the assignable argument.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure(java.util.Map<java.lang.String,?> configs, boolean isKey)
protected org.apache.kafka.common.serialization.Serializer
findDelegate(java.lang.Object data, java.util.Map<java.lang.Class<?>,org.apache.kafka.common.serialization.Serializer> delegates)
Determine the serializer for the data type.protected boolean
isAssignable()
Returns true iffindDelegate(Object, Map)
should consider assignability to the key rather than an exact match.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)
-
-
-
Constructor Detail
-
DelegatingByTypeSerializer
public DelegatingByTypeSerializer(java.util.Map<java.lang.Class<?>,org.apache.kafka.common.serialization.Serializer> delegates)
Construct an instance with the map of delegates; keys matched exactly.- Parameters:
delegates
- the delegates.
-
DelegatingByTypeSerializer
public DelegatingByTypeSerializer(java.util.Map<java.lang.Class<?>,org.apache.kafka.common.serialization.Serializer> delegates, boolean assignable)
Construct an instance with the map of delegates; keys matched exactly or if the target object is assignable to the key, depending on the assignable argument. If assignable, entries are checked in the natural entry order so an ordered map such as aLinkedHashMap
is recommended.- Parameters:
delegates
- the delegates.assignable
- whether the target is assignable to the key.- Since:
- 2.8.3
-
-
Method Detail
-
isAssignable
protected boolean isAssignable()
Returns true iffindDelegate(Object, Map)
should consider assignability to the key rather than an exact match.- Returns:
- true if assigable.
- Since:
- 2.8.3
-
configure
public void configure(java.util.Map<java.lang.String,?> configs, boolean isKey)
- Specified by:
configure
in interfaceorg.apache.kafka.common.serialization.Serializer<java.lang.Object>
-
serialize
public byte[] serialize(java.lang.String topic, java.lang.Object data)
- Specified by:
serialize
in interfaceorg.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 interfaceorg.apache.kafka.common.serialization.Serializer<java.lang.Object>
-
findDelegate
protected org.apache.kafka.common.serialization.Serializer findDelegate(java.lang.Object data, java.util.Map<java.lang.Class<?>,org.apache.kafka.common.serialization.Serializer> delegates)
Determine the serializer for the data type.- Parameters:
data
- the data.delegates
- the available delegates.- Returns:
- the delgate.
- Throws:
org.apache.kafka.common.errors.SerializationException
- when there is no match.- Since:
- 2.8.3
-
-