Reputation: 267
I am creating JSON object as below
org.json.JSONObject json = new JSONObject(jsonString);
I want to send this object to queue on ActiveMQ. I was trying to use following API
objectMessage.setObject(json);
But as json object is not serializable, compiler is throwing error.
If I convert json object to String then it is working.
Is there any way I can directly transfer json object (without converting to String) to queue?
Upvotes: 1
Views: 7171
Reputation: 4316
Don't use ..jms.ObjectMessage, it leads to all sorts of pain, suffering and anger. Serialize your JSON to a string and send a ..jms.TextMessage instead.
That being said.. it all depends on your use case. There are Architectural principles that favor text-based formats during transport for cross-platform and service independence reasons. If this is a use case where the same app is sharing data b/w itself over JMS, the argument could be made to justify using ObjectMessages. To do that update your JSON pojo's to ".. implement Serializable" and then jms.ObjectMessage will work.
Upvotes: 2