spring boot rabbitmq MappingJackson2MessageConverter custom object conversion
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
When Spring Boot talks to RabbitMQ with custom Java objects, the real problem is not RabbitMQ itself. It is message conversion: the sender must turn the object into JSON, and the receiver must turn the JSON back into the expected Java type in a way both sides agree on.
Use The JSON Converter On Both Sides
For RabbitMQ in Spring AMQP, the practical converter is usually Jackson2JsonMessageConverter. That is the component most people mean when they refer to Jackson-based object conversion in RabbitMQ messaging.
Configure it once and apply it to the RabbitTemplate:
Without this, Spring often falls back to a simpler converter that is not what you want for JSON custom objects.
Send And Receive A Custom Object
Suppose the message payload is an OrderCreatedEvent:
Publishing is then straightforward:
On the receiving side, the listener can accept the Java type directly if the converter is configured consistently:
This is the main payoff: no manual JSON parsing in the business logic.
Customize The ObjectMapper When The Payload Needs It
If your object contains Java time types, naming conventions, or other custom serialization rules, inject a customized ObjectMapper into the converter.
This is usually a better fix than forcing the application layer to serialize special fields by hand.
Why Conversion Sometimes Fails
The most common failure mode is that one side sends JSON, but the other side is not actually using the same converter or the same type expectations. Another common problem is missing getters, setters, or a no-argument constructor on the payload type.
If the listener expects a custom object and receives a raw byte[] or String, that usually means the converter configuration never got applied where you thought it did.
Common Pitfalls
- Configuring the JSON converter for the sender but not the listener side.
- Expecting custom object conversion while Spring is still using
SimpleMessageConverter. - Forgetting a no-argument constructor or normal bean accessors on the payload type.
- Ignoring
ObjectMappercustomization when the payload includes dates or other special fields. - Assuming any Jackson-based class name works interchangeably across Spring Messaging and Spring AMQP without checking the actual RabbitMQ configuration point.
Summary
- For Spring Boot and RabbitMQ, use the Jackson JSON message converter consistently on both send and receive paths.
- '
RabbitTemplate.convertAndSend(...)can publish a normal Java object once the converter is configured.' - '
@RabbitListenercan receive the custom object directly when the conversion metadata lines up.' - If conversion fails, inspect the converter wiring before changing the business logic.

