Spring JMS supports Message Converters. Some Message Converters are provided out of the box :
Message Converter | What It Does |
SimpleMessageConverter | Converts Strings to and from TextMessage, byte arrays to and from BytesMessage, Maps to and from MapMessage, and Serializable objects to and from ObjectMessage. Spring uses SimpleMessageConverter by default |
MappingJackson2MessageConverter | Uses the Jackson 2 JSON library to convert messages to and from JSON |
MarshallingMessageConverter | Uses JAXB to convert messages to and from XML |
MessagingMessageConverter | Converts a Message from the messaging abstraction to and from a Message using an underlying MessageConverter for the payload and a JmsHeaderMapper to map the JMS headers to and from standard message headers |
Developer can create custom message conversion functionality. Custom converter class must implement MessageConverter interface, which has two methods :
- Message toMessage(Object object, Session session) – converts Java object to JMS message using the supplied Session to create the message object. Returns JMS Message.
- Object fromMessage(Message message) – converts JMS message to Java object