From eee1b1385c2864a32370a8e4758294d5efbe4cd5 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Mon, 2 Mar 2020 13:13:31 +0100 Subject: [PATCH] GH-1920 Add MessageConverter filtering logic This way we ensure that only custom converters and converters defined by stream are included effectively eliminating the possibility of other auto-configuration interfering with their converters Resolves #1920 --- .../stream/config/ContentTypeConfiguration.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/ContentTypeConfiguration.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/ContentTypeConfiguration.java index 1d37024da..33ca78916 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/ContentTypeConfiguration.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/ContentTypeConfiguration.java @@ -28,7 +28,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Role; import org.springframework.integration.context.IntegrationContextUtils; -import org.springframework.integration.support.converter.DefaultDatatypeChannelMessageConverter; import org.springframework.messaging.converter.CompositeMessageConverter; import org.springframework.messaging.converter.MessageConverter; @@ -47,7 +46,7 @@ class ContentTypeConfiguration { List customMessageConverters) { customMessageConverters = customMessageConverters.stream() - .filter(c -> !(c instanceof DefaultDatatypeChannelMessageConverter)).collect(Collectors.toList()); + .filter(c -> isConverterEligible(c)).collect(Collectors.toList()); CompositeMessageConverterFactory factory = new CompositeMessageConverterFactory(customMessageConverters, objectMapperObjectProvider.getIfAvailable(ObjectMapper::new)); @@ -55,4 +54,18 @@ class ContentTypeConfiguration { return factory.getMessageConverterForAllRegistered(); } + /* + * We want to filter out all non-stream MessageConverters, given that other + * auto-configurations may interfere with their MessageConverters. + */ + private boolean isConverterEligible(Object messageConverter) { + String messageConverterName = messageConverter.getClass().getName(); + if (messageConverterName.startsWith("org.springframework.cloud.")) { + return true; + } + else if (!messageConverterName.startsWith("org.springframework.")) { + return true; + } + return false; + } }