My consumer configured as follows:
@Bean
public Consumer<Message<List<Foo>>> consumer() {
return message -> {
message.getPayload().forEach(it -> {
// process
})
};
}
I've also configured ErrorHandlingDeserializer which may produce KafkaNull values in message payload collection. The problem that I cannot filter such values because accessing collection with forEach() method produces ClassCastException:
java.lang.ClassCastException: class org.springframework.kafka.support.KafkaNull cannot be cast to class Foo
How can I exclude KafkaNull values from processing (without changing signature of consumer to Consumer<Message<List<Object>>>)?