You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In what version(s) of Spring for Apache Kafka are you seeing this issue?
2.8.3
Describe the bug
DelegatingByTypeSerializer does not support null payload messages (Tombstone)
To Reproduce
@Bean
DefaultKafkaProducerFactoryCustomizer kafkaProducerFactoryCustomizer() {
return producerFactory -> producerFactory.setValueSerializer((Serializer) new DelegatingByTypeSerializer (
Map.of(
byte[].class, new ByteArraySerializer(),
AvroEvent.class, new KafkaAvroSerializer(),
XmlEvent.class, new CustumXmlSerializer())));
}
kafkaTemplate.send (key="abcd", value=null)
Expected behavior
Messages with value = null could be sent via KafkaTemplate
Actual behavior
Caused by: java.lang.NullPointerException: null
at org.springframework.kafka.support.serializer.DelegatingByTypeSerializer.findDelegate(DelegatingByTypeSerializer.java:114) ~[spring-kafka-2.8.3.jar:2.8.3]
at org.springframework.kafka.support.serializer.DelegatingByTypeSerializer.serialize(DelegatingByTypeSerializer.java:99) ~[spring-kafka-2.8.3.jar:2.8.3]
at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:929) ~[kafka-clients-3.0.0.jar:na]
at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:889) ~[kafka-clients-3.0.0.jar:na]
at org.springframework.kafka.core.DefaultKafkaProducerFactory$CloseSafeProducer.send(DefaultKafkaProducerFactory.java:993) ~[spring-kafka-2.8.3.jar:2.8.3]
at org.springframework.kafka.core.KafkaTemplate.doSend(KafkaTemplate.java:649) ~[spring-kafka-2.8.3.jar:2.8.3]
at org.springframework.kafka.core.KafkaTemplate.send(KafkaTemplate.java:429) ~[spring-kafka-2.8.
Workarround
public class CustomDelegatingByTypeSerializer extends DelegatingByTypeSerializer {
public CustomDelegatingByTypeSerializer(Map<Class<?>, Serializer> delegates) {
super(delegates);
}
@Override
protected Serializer findDelegate(Object data, Map<Class<?>, Serializer> delegates) {
if (data == null) {
return new ByteArraySerializer();
}
return super.findDelegate(data, delegates);
}
}
Solution / proposition
All spring-kafka Serializer support messages with null values, this is why it's good if DelegatingByTypeSerializer can also handle it.
The text was updated successfully, but these errors were encountered:
In what version(s) of Spring for Apache Kafka are you seeing this issue?
2.8.3
Describe the bug
DelegatingByTypeSerializer does not support null payload messages (Tombstone)
To Reproduce
kafkaTemplate.send (key="abcd", value=null)
Expected behavior
Messages with value = null could be sent via KafkaTemplate
Actual behavior
Caused by: java.lang.NullPointerException: null
at org.springframework.kafka.support.serializer.DelegatingByTypeSerializer.findDelegate(DelegatingByTypeSerializer.java:114) ~[spring-kafka-2.8.3.jar:2.8.3]
at org.springframework.kafka.support.serializer.DelegatingByTypeSerializer.serialize(DelegatingByTypeSerializer.java:99) ~[spring-kafka-2.8.3.jar:2.8.3]
at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:929) ~[kafka-clients-3.0.0.jar:na]
at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:889) ~[kafka-clients-3.0.0.jar:na]
at org.springframework.kafka.core.DefaultKafkaProducerFactory$CloseSafeProducer.send(DefaultKafkaProducerFactory.java:993) ~[spring-kafka-2.8.3.jar:2.8.3]
at org.springframework.kafka.core.KafkaTemplate.doSend(KafkaTemplate.java:649) ~[spring-kafka-2.8.3.jar:2.8.3]
at org.springframework.kafka.core.KafkaTemplate.send(KafkaTemplate.java:429) ~[spring-kafka-2.8.
Workarround
public class CustomDelegatingByTypeSerializer extends DelegatingByTypeSerializer {
}
Solution / proposition
All spring-kafka Serializer support messages with null values, this is why it's good if DelegatingByTypeSerializer can also handle it.
The text was updated successfully, but these errors were encountered: