Is there a way to be able to ignore unknown properties of a payload and still deserialize it to the target class when using Spring Cloud Stream binder?
import .springframework.messaging.Message;
....
@Bean
Consumer<Message<MyClass>> consumeMessage(Processor processor) {
return processor::processMessage;
}
....
public class Processor {
public void processMessage(Message<MyClass> myMessage) {
MyClass myClass = myMessage.getPayload();
}
}
With the default setup, when the payload on Kafka has an extra property, myMessage.getPayload() cannot be cast to MyClass as it is a byte array.
I have tried some customization, such as:
@Bean
public MessagingMessageConverter myConverterBean() {
MessagingMessageConverter converter = new MessagingMessageConverter();
converter.setMessagingConverter(new MappingJacksonParameterizedConverter());
return converter;
}
but the payload is mapped to an Object instead of MyClass and I get java.util.LinkedHashMap cannot be cast
so I don't think I am on the right track.
I also need to keep my solution quite generic, to be able to apply it to multiple consumers where payload deserialization should be more relaxed.
Is there any way to achieve this?