Is there a standard way for me to add my own custom object to a Map and then have it properly marshalled in a MapMessage? Currently I get the Invalid Object Type message. I noticed that WebSphere has a solution but I am looking for something that is not bound to a particular AS, if there is no such method, maybe something supported by JBoss would work.
How to do it in WebSphere: http://publib.boulder.ibm.com/infocenter/dmndhelp/v6rxmx/index.jsp?topic=/com.ibm.websphere.wesb.doc/ref/rwesb_jmscustombindings.html
A JMS map message's map only supports primitives and strings (and their arrays) as values. From the javadoc:
You would be better off using an ObjectMessage and write your serialized objects to a map and then send the map as the payload of the ObjectMessage. That way, you can still have the name/value map access style but without the limitation of types.
With
JsmTemplate
in Spring (2.5, 3.1), if you want to send aMap
throughjmsTemplate.convertAndSend()
where the Map contains a non-primitive object, you could cast the Map asSerializable
and callsend(MessageCreator)
. This way:This way jmsTemplate will work with the Map as Serializable and will send an
ObjectMessage
over the wire.Note that the listener consuming messages will have to be able to read the ObjectMessage and then cast it as Map again. Be aware that you have to had the corresponding classes at both sides of the wire, and of course, the objects inside the Map has to be Serializable!