From 717cf647f486b9a615eb55634c07a790310aac26 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Thu, 28 Feb 2019 17:34:56 +0100 Subject: [PATCH] GH-1614 Added Expression Serializer to ObjectMapper Resolves #1614 --- .../binder/AbstractMessageChannelBinder.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/AbstractMessageChannelBinder.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/AbstractMessageChannelBinder.java index 1041866c5..d6828db34 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/AbstractMessageChannelBinder.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/AbstractMessageChannelBinder.java @@ -16,13 +16,18 @@ package org.springframework.cloud.stream.binder; +import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; import org.apache.commons.logging.Log; import org.reactivestreams.Publisher; @@ -44,6 +49,7 @@ import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.context.Lifecycle; import org.springframework.context.support.GenericApplicationContext; +import org.springframework.expression.Expression; import org.springframework.integration.channel.AbstractMessageChannel; import org.springframework.integration.channel.AbstractSubscribableChannel; import org.springframework.integration.channel.DirectChannel; @@ -145,6 +151,10 @@ public abstract class AbstractMessageChannelBinder containerCustomizer, @Nullable MessageSourceCustomizer sourceCustomizer) { + SimpleModule module = new SimpleModule(); + module.addSerializer(Expression.class, new ExpressionSerializer(Expression.class)); + objectMapper.registerModule(module); + this.headersToEmbed = headersToEmbed == null ? new String[0] : headersToEmbed; this.provisioningProvider = provisioningProvider; this.containerCustomizer = containerCustomizer == null ? (c, q, g) -> { @@ -464,7 +474,7 @@ public abstract class AbstractMessageChannelBinder messageSource = resources.getSource(); if (messageSource instanceof BeanFactoryAware) { - ((BeanFactoryAware)messageSource).setBeanFactory(getApplicationContext().getBeanFactory()); + ((BeanFactoryAware) messageSource).setBeanFactory(getApplicationContext().getBeanFactory()); } bindingTarget.setSource(messageSource); if (resources.getErrorInfrastructure() != null) { @@ -1146,4 +1156,17 @@ public abstract class AbstractMessageChannelBinder { + + protected ExpressionSerializer(Class t) { + super(t); + } + + @Override + public void serialize(Expression value, JsonGenerator gen, SerializerProvider provider) throws IOException { + gen.writeString(value.getExpressionString()); + } + } + }