diff --git a/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/MessageChannelConfigurerTests.java b/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/MessageChannelConfigurerTests.java index a3fbb59d8..e22d74516 100644 --- a/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/MessageChannelConfigurerTests.java +++ b/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/MessageChannelConfigurerTests.java @@ -19,22 +19,28 @@ import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.cloud.stream.annotation.Bindings; import org.springframework.cloud.stream.annotation.EnableBinding; +import org.springframework.cloud.stream.converter.CompositeMessageConverterFactory; import org.springframework.cloud.stream.messaging.Sink; import org.springframework.context.annotation.PropertySource; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.MessagingException; +import org.springframework.messaging.converter.CompositeMessageConverter; +import org.springframework.messaging.converter.MessageConverter; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.tuple.Tuple; +import org.springframework.util.MimeTypeUtils; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -51,6 +57,9 @@ public class MessageChannelConfigurerTests { @Autowired @Bindings(TestSink.class) private Sink testSink; + @Autowired + private CompositeMessageConverterFactory messageConverterFactory; + @Autowired private ObjectMapper objectMapper; @@ -73,8 +82,18 @@ public class MessageChannelConfigurerTests { } @Test - public void testObjectMapperConfig() { - assertTrue("SerializationFeature 'WRITE_DATES_AS_TIMESTAMPS' should be disabled", !objectMapper.getSerializationConfig().isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)); + public void testObjectMapperConfig() throws Exception { + CompositeMessageConverter compositeMessageConverter = messageConverterFactory.getMessageConverterForType(MimeTypeUtils.APPLICATION_JSON); + List converters = compositeMessageConverter.getConverters(); + for (MessageConverter converter : converters) { + DirectFieldAccessor converterAccessor = new DirectFieldAccessor(converter); + ObjectMapper objectMapper = (ObjectMapper) converterAccessor.getPropertyValue("objectMapper"); + // assert that the ObjectMapper used by the converters is compliant with the Boot configuration + assertTrue("SerializationFeature 'WRITE_DATES_AS_TIMESTAMPS' should be disabled", + !objectMapper.getSerializationConfig().isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)); + // assert that the globally set bean is used by the converters + assertTrue(objectMapper == this.objectMapper); + } } @EnableBinding(Sink.class) diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/ChannelBindingServiceConfiguration.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/ChannelBindingServiceConfiguration.java index abf02e513..2751e49a4 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/ChannelBindingServiceConfiguration.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/ChannelBindingServiceConfiguration.java @@ -85,7 +85,7 @@ public class ChannelBindingServiceConfiguration { @Autowired private MessageBuilderFactory messageBuilderFactory; - @Lazy @Autowired(required = false) + @Autowired(required = false) private ObjectMapper objectMapper; /** diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/SpelExpressionConverterConfiguration.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/SpelExpressionConverterConfiguration.java index da1256a4e..4f59dc40b 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/SpelExpressionConverterConfiguration.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/SpelExpressionConverterConfiguration.java @@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.properties.ConfigurationPropertiesBinding; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; import org.springframework.core.convert.converter.Converter; import org.springframework.expression.EvaluationContext; import org.springframework.expression.Expression; @@ -55,6 +56,7 @@ public class SpelExpressionConverterConfiguration { @Autowired @Qualifier(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME) + @Lazy private EvaluationContext evaluationContext; @Override