Jackson2JsonMessageConverter is a Spring AMQP MessageConverter that serialises Java objects to JSON when you send them to RabbitMQ and deserialises JSON back into Java objects when you receive them. Without it, RabbitTemplate uses Java serialisation through SimpleMessageConverter, which produces opaque binary payloads that other languages cannot read and that carry security risks.
With the JSON converter, messages are readable, language-neutral and easy to debug in the RabbitMQ management UI.
The converter uses a Jackson ObjectMapper to write the payload as UTF-8 JSON and sets the message content type to application/json. It also adds a __TypeId__ header holding the fully qualified class name, so a Java consumer can rebuild the right type. When receiving, it reads that header (or the listener method's parameter type) to decide what to create.
Version note: in Spring AMQP releases built on Jackson 3 (the 4.x line, used with Spring Boot 4), the Jackson 3 based JacksonJsonMessageConverter is the preferred class and the Jackson 2 one is deprecated. Check the release notes of your Spring AMQP version; the concepts below are the same.
Spring Boot auto-configures RabbitTemplate and listener containers with a single MessageConverter bean when one exists, so you only declare the bean.
If you configure the template yourself, set the converter explicitly:
Use a record or class as the payload; Jackson 2.12 and later handles records.
The message body on the broker looks like this:
By default the producer's __TypeId__ header names its own class, for example com.shop.orders.OrderCreated. If the consumer lives in a different package or a different service, that class may not exist there. Two safe fixes:
@RabbitListener has a single payload parameter, by using setTypePrecedence(TypePrecedence.INFERRED).setTrustedPackages limits which packages may be instantiated from the type header. Do not trust "*" on a queue that accepts messages from untrusted producers, since that allows attacker-chosen classes to be deserialised.
You can pass your own ObjectMapper to control dates, unknown properties and naming:
A malformed message throws MessageConversionException. Spring AMQP treats it as fatal and does not requeue it endlessly by default, so configure a dead-letter queue to inspect bad messages.
RabbitTemplate falls back to SimpleMessageConverter, which sends strings and byte arrays as is and uses Java serialisation for Serializable objects.
The __TypeId__ header names a class that the consumer does not have. Use inferred type precedence or an id-to-class mapping.
No. Restrict trusted packages to your own model classes.
Yes. The body is plain JSON with content type application/json; the __TypeId__ header is simply ignored.
Jackson2JsonMessageConverter makes RabbitMQ messages JSON instead of Java-serialised bytes. Declare it as a bean, let Spring Boot wire it into RabbitTemplate and listeners, use inferred type mapping across services, restrict trusted packages, and note that Jackson 3 based Spring AMQP versions introduce a renamed converter.