I am creating JSON object as below
我正在创建JSON对象,如下所示
org.json.JSONObject json = new JSONObject(jsonString);
I want to send this object to queue on ActiveMQ. I was trying to use following API
我想将此对象发送到ActiveMQ上的队列。我试图使用以下API
objectMessage.setObject(json);
But as json object is not serializable, compiler is throwing error.
但由于json对象不可序列化,编译器会抛出错误。
If I convert json object to String then it is working.
如果我将json对象转换为String,那么它正在工作。
Is there any way I can directly transfer json object (without converting to String) to queue?
有什么办法可以直接将json对象(不转换为String)转移到队列中吗?
1 个解决方案
#1
1
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.
不要使用..jms.ObjectMessage,它会导致各种各样的痛苦,痛苦和愤怒。将JSON序列化为字符串并发送..jms.TextMessage。
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.
这就是说..这一切都取决于你的用例。由于跨平台和服务独立性原因,在运输过程中存在支持基于文本的格式的架构原则。如果这是一个用例,其中相同的应用程序通过JMS共享数据b / w本身,则可以使用该参数来证明使用ObjectMessages。为此,请将您的JSON pojo更新为“..实现Serializable”,然后jms.ObjectMessage将起作用。
#1
1
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.
不要使用..jms.ObjectMessage,它会导致各种各样的痛苦,痛苦和愤怒。将JSON序列化为字符串并发送..jms.TextMessage。
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.
这就是说..这一切都取决于你的用例。由于跨平台和服务独立性原因,在运输过程中存在支持基于文本的格式的架构原则。如果这是一个用例,其中相同的应用程序通过JMS共享数据b / w本身,则可以使用该参数来证明使用ObjectMessages。为此,请将您的JSON pojo更新为“..实现Serializable”,然后jms.ObjectMessage将起作用。