The MessageConverter interface in Spring AMQP converts Java objects to RabbitMQ Message objects (body bytes plus properties) when you send, and converts incoming messages back to Java objects when you receive. It is what lets RabbitTemplate and @RabbitListener methods work with typed payloads instead of raw byte[].
The interface has two methods, toMessage(Object, MessageProperties) and fromMessage(Message). Picking the right implementation decides the wire format (Java serialization, plain text, JSON), the content type header, and how safe and interoperable your messaging is.
RabbitTemplate.convertAndSend(...) calls toMessage before publishing, and receiveAndConvert(...) or a listener container calls fromMessage after delivery. A failure throws MessageConversionException, which the listener container treats as a fatal, non-retryable error by default so a bad message is not redelivered forever.
| Converter | Content type | Typical use |
|---|---|---|
SimpleMessageConverter (default) | text/plain, application/octet-stream, application/x-java-serialized-object | String, byte[] and Serializable objects |
Jackson2JsonMessageConverter | application/json | JSON for POJOs and records (Jackson 2) |
JacksonJsonMessageConverter | application/json | JSON on Jackson 3, introduced with Spring AMQP 4.0; the Jackson 2 converter is deprecated there |
ContentTypeDelegatingMessageConverter | any | Chooses a converter by the contentType header |
MarshallingMessageConverter | application/xml | XML through a Spring Marshaller |
MessagingMessageConverter | per payload | Bridges to Spring's org.springframework.messaging.Message |
Check your Spring AMQP version: Spring Boot 3.x ships Spring AMQP 3.x with the Jackson 2 converter, while Spring Boot 4 moves to Spring AMQP 4.x and Jackson 3.
Java serialization is the default for non-text objects, and it is a poor choice: it ties both sides to the same class files and is a known security risk. Use JSON instead. With Spring Boot, declaring a MessageConverter bean is enough, because auto-configuration applies it to the RabbitTemplate and to the listener container factory.
The published message carries content_type: application/json and a JSON body such as {"orderId":"A-1","quantity":2}.
By default the JSON converter writes a __TypeId__ header containing the fully qualified class name, and the receiver uses it to pick the target class. That breaks when producer and consumer use different packages or are written in different languages. Two common fixes:
DefaultJackson2JavaTypeMapper and TypePrecedence.INFERRED, so the parameter type is used instead of the header.setIdClassMapping, so only a short name such as orderCreated travels in the header.Restricting trusted packages stops a message from instantiating arbitrary classes.
SimpleMessageConverter deserializes application/x-java-serialized-object messages, which can be abused for deserialization attacks if the broker is reachable by untrusted publishers. Since Spring AMQP 1.5.5 the converter has an allowed-list (setAllowedListPatterns), and you should set it explicitly if you must keep Java serialization. Better still, switch to JSON.
Implement MessageConverter for formats such as Protobuf or Avro. Set the content type so consumers can recognise the payload.
Register it as a bean, or call rabbitTemplate.setMessageConverter(...) and factory.setMessageConverter(...) yourself in a non-Boot setup.
SimpleMessageConverter. It handles String, byte[] and Serializable objects and nothing else, so POJOs sent over it use Java serialization.
Define a Jackson2JsonMessageConverter bean (or the Jackson 3 equivalent on Spring AMQP 4). Spring Boot applies it to RabbitTemplate and @RabbitListener automatically.
Usually the __TypeId__ header names a class the consumer does not have, or the body is not valid for the target type. Infer the type from the method parameter or map type ids, and check trusted packages.
Yes. ContentTypeDelegatingMessageConverter selects a converter from the message content type.
MessageConverter is the translation layer between Java objects and AMQP messages. Replace the Java-serialization default with a JSON converter, control type mapping so services stay decoupled, restrict trusted packages, and use a custom or delegating converter when you need other formats.