liveBook · Manning

SimpleMessageConverter

As explained in Spring in Action, Sixth Edition

SimpleMessageConverter is Spring's JMS converter that performs basic payload conversion and requires sent objects to implement Serializable for object messages.

SimpleMessageConverter is the default converter for both JmsTemplate and RabbitTemplate. It turns supported application values into messages so you can pass a value to convertAndSend() instead of creating a message yourself. The two templates use their respective messaging APIs, so their supported conversions differ. section 9.1.2 section 9.2.2

Table 9.3 Spring message converters for common conversion tasks (all in the org.springframework.jms.support.converter package) (view table figure)

Message converter

What it does

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

SimpleMessageConverter

Converts a String to and from a TextMessage, byte arrays to and from a BytesMessage, a Map to and from a MapMessage, and a Serializable to and from an ObjectMessage

For JMS, the conversion table shows the matching message type: String to TextMessage, byte arrays to BytesMessage, Map to MapMessage, and Serializable objects to ObjectMessage. section 9.1.2

Send an order through JMS

Call jms.convertAndSend("tacocloud.order.queue", order) to send an order without constructing a JMS Message. With the default converter, an order sent as an object must implement Serializable. section 9.1.2

If that Serializable requirement does not suit the application, declare a MappingJackson2MessageConverter bean to use JSON for JMS messages instead. Configure its type-ID property so the receiver can determine the incoming object's type. For RabbitTemplate, the default SimpleMessageConverter supports String, byte arrays, and Serializable types; a Jackson2JsonMessageConverter bean can replace it for JSON conversion. section 9.1.2 section 9.2.2

How Spring in Action, Sixth Edition covers it

How deep it goes
Defines supported JMS message mappings and RabbitTemplate payload types, then shows configuration alternatives without implementing the converter.
Examples
Uses a queued order, a JMS conversion table, and JSON converter bean declarations.
What it assumes
Assumes an application already sends messages with JmsTemplate or RabbitTemplate, while defining the converter's role through convertAndSend().
What you can do after
Apply it via JmsTemplate or RabbitTemplate, and configure a JSON converter bean when default conversion is unsuitable.
How it connects
Connects MessageConverter, convertAndSend(), Serializable, JMS ObjectMessage, RabbitTemplate, and JSON message converters.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.