-1

Consider the following class :

public class MsgReceiver<MSG> extends AbstractMsgReceiver<MSG> implements 
MsgReceiver<MSG> {

@KafkaListener( // necessary properties )
public void receiveMessage(@Headers Map<String, Object> headers, @Payload ConsumerRecord<String, 
Object> payload) {

    super.receiveMessage(headers,(MSG) (payload.value())); // line foobar
}

The payload.value() is of type LinkedHashMap and when I use this class, MSG can be any of my custom POJO class. I get ClassCastException when converting from LinkedMashMap to my POJO class on line foobar. How can I resolve this ?

want2learn
  • 2,471
  • 2
  • 20
  • 37
definepi314
  • 63
  • 1
  • 10

2 Answers2

0

Try using jackson mapper, or any mapper I'd say. I have been using jackson mapper for kafka queue listeners, works perfectly Find details here

Michael
  • 76
  • 5
0

payload.value() returns iterator object. It might be the issue in typecasting. Check your POJO class for it.