title: SpringBoot RabbitMq parse json message auto of the box
body: <p>I have my springboot app which connects to a RabbitMQ queue where I push messages in specified Json format, for example: <code>{"messageId":"de5fe5a3-1831-4b87-891d-e7a4c29295b4","message":{"listingId":"2"},"errors":[]}</code> I did created a corresponding Java DTO obejct, but I don't know how to parse a rabbbitMq message straight into java object. I have found a way to do it with Jackson ObjectMapper however I would 
  like spring to do it by himself instead of me </p>
  
  <p>My DTO</p>
  
  <pre><code>    @Data
      @JsonIgnoreProperties(ignoreUnknown = true)
      final class ListingMessage {
          private final String messageId;
          private final Message message;
          private final List&lt;String&gt; errors;
  
          @Data
          static final class Message {
              private final String listingId;
          }
      }
  </code></pre>
  
  <p>And I would like to achieve somehting like that:</p>
  
  <pre><code>    @Component
      @Slf4j
      final class ListingMessageListener {
  
          private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
  
          @RabbitListener(queues = "${rabbitmq.queues}")
          public void receiveMessage(final ListingMessage message) {
                  doSomeStuff(message); 
           }
         }
  </code></pre>
  
  <p>Instead of </p>
  
  <pre><code>@Component
  @Slf4j
  final class ListingMessageListener {
  
      private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
  
      @RabbitListener(queues = "${rabbitmq.queues}")
      public void receiveMessage(final Message message) {
  
          final String json = new String(message.getBody());
          try {
              final ListingMessage listingMessage = OBJECT_MAPPER.readValue(json, ListingMessage.class);
              doSomeStuff(listingMessage);
          }catch(final Exception e){e.printStackTrace();}
       }
     }
  </code></pre>
  
  <p>EDIT. When I added  Jackson2JsonMessageConverter</p>
  
  <pre><code>    @Bean
      public Jackson2JsonMessageConverter jackson2JsonMessageConverter(){
          return new Jackson2JsonMessageConverter();
      }
  </code></pre>
  
  <p>I got an exception</p>
  
  <pre><code>org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener method could not be invoked with the incoming message
  Endpoint handler details:
  Method [public void com.listingsdatapipeline.rabbitmq.ListingMessageListener.receiveMessage(com.listingsdatapipeline.rabbitmq.ListingMessage)]
  Bean [com.listingsdatapipeline.rabbitmq.ListingMessageListener@626df4e5]
      at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:191) ~[spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
      at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:126) ~[spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1414) ~[spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1337) ~[spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1324) ~[spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1303) ~[spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:817) [spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:801) [spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$700(SimpleMessageListenerContainer.java:77) [spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1042) [spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
      at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171]
  Caused by: org.springframework.messaging.converter.MessageConversionException: Cannot convert from [[B] to [com.listingsdatapipeline.rabbitmq.ListingMessage] for GenericMessage [payload=byte[167], headers={amqp_receivedDeliveryMode=NON_PERSISTENT, amqp_receivedRoutingKey=changes-consumer-de, amqp_deliveryTag=1, amqp_consumerQueue=changes-consumer-de, content-type=application/json, amqp_redelivered=false, id=8fb1f2ad-96dd-3d25-c77d-82f741cfa788, amqp_consumerTag=amq.ctag-DfMMARR_KXMXyNJMoEXyAQ, timestamp=1539177836655}]
      at org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver.resolveArgument(PayloadArgumentResolver.java:144) ~[spring-messaging-5.0.9.RELEASE.jar:5.0.9.RELEASE]
      at org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:116) ~[spring-messaging-5.0.9.RELEASE.jar:5.0.9.RELEASE]
      at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:137) ~[spring-messaging-5.0.9.RELEASE.jar:5.0.9.RELEASE]
      at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:109) ~[spring-messaging-5.0.9.RELEASE.jar:5.0.9.RELEASE]
      at org.springframework.amqp.rabbit.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:51) ~[spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
      at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:188) ~[spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
      ... 10 common frames omitted
  </code></pre>