java.lang.ClassCastException: class com.solacesystems.jcsmp.impl.BytesMessageImpl cannot be cast to class com.solacesystems.jcsmp.TextMessage (com.solacesystems.jcsmp.impl.BytesMessageImpl and com.solacesystems.jcsmp.TextMessage are in unnamed module of loader ‘app’)
What i get it is SolaceBytesMessage, cant not case to TextMessage, Cant cast To Message, because message.getBody() wont work solace has not implemented it and i cant provide class name arguments.
I need to no how do we get the actual message from this bytes message ?
Hi Team,
We also get the same issue when spring cloud stream reply the message to non spring cloud stream service.
com.solacesystems.jcsmp.impl.BytesMessageImpl cannot be cast to com.solacesystems.jcsmp.TextMessage"
Code:
textMessage.setText(((TextMessage)replyMessage).getText());
Do we need to type cast to BytesMessage and use getData API and convert to String?
You will not be able to cast from BytesMessage to TextMessage. You will need to grab the bytes from the payload and convert to string.
I would do something like the following:
if (replyMessage instanceof TextMessage) {
textMessage.setText(((TextMessage)replyMessage).getText());
} else if (replyMessage instanceof BytesMessage) {
textMessage.setText(new String(((BytesMessage)replyMessage).getData()));
} else ...
Haven’t tested the above so I will put that caveat in. Plus there is likely a more efficient way of doing this, but this is the simplest.