From 999090f63df91883fd3c5090176d7a67a6879f7c Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 15 Jul 2016 13:59:09 -0400 Subject: [PATCH] AMQP-618: Add `contentType` note into JSON Docs JIRA: https://jira.spring.io/browse/AMQP-618 Also, in the `Jackson2JsonMessageConverter`, wrap `log.warn()` with String concatenation into `log.isWarnEnabled()` --- .../support/converter/Jackson2JsonMessageConverter.java | 6 ++++-- src/reference/asciidoc/amqp.adoc | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/spring-amqp/src/main/java/org/springframework/amqp/support/converter/Jackson2JsonMessageConverter.java b/spring-amqp/src/main/java/org/springframework/amqp/support/converter/Jackson2JsonMessageConverter.java index db3104b2..ece521d1 100644 --- a/spring-amqp/src/main/java/org/springframework/amqp/support/converter/Jackson2JsonMessageConverter.java +++ b/spring-amqp/src/main/java/org/springframework/amqp/support/converter/Jackson2JsonMessageConverter.java @@ -159,8 +159,10 @@ public class Jackson2JsonMessageConverter extends AbstractJsonMessageConverter { } } else { - log.warn("Could not convert incoming message with content-type [" - + contentType + "]"); + if (log.isWarnEnabled()) { + log.warn("Could not convert incoming message with content-type [" + + contentType + "]"); + } } } if (content == null) { diff --git a/src/reference/asciidoc/amqp.adoc b/src/reference/asciidoc/amqp.adoc index 3f770551..c46c8771 100644 --- a/src/reference/asciidoc/amqp.adoc +++ b/src/reference/asciidoc/amqp.adoc @@ -2268,6 +2268,10 @@ The property is actually on the converter's `DefaultJackson2JavaTypeMapper` but for convenience. If you inject a custom type mapper, you should set the property on the mapper instead. +NOTE: When converting from the `Message`, an incoming `MessageProperties.getContentType()` must be JSON-compliant (the logic `contentType.contains("json")` is used). +Otherwise, a `WARN` log message `Could not convert incoming message with content-type [...]`, is emitted and `message.getBody()` is returned as is - as a `byte[]``. +So, to meet the `Jackson2JsonMessageConverter` requirements on the consumer side, the producer must add the `contentType` message property, e.g. as `application/json`, `text/x-json` or simply use the `Jackson2JsonMessageConverter`, which will set the header automatically. + [source, java] ---- @RabbitListener