From 694c7fa1bbc78ae325ecd0810736abf4e13ab59f Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Wed, 24 Jul 2019 13:57:17 +0200 Subject: [PATCH] Adding support for extracting payload only for cases where conversion is not necessary --- .../BeanFactoryAwareFunctionRegistry.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/BeanFactoryAwareFunctionRegistry.java b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/BeanFactoryAwareFunctionRegistry.java index 90fa87626..3cc761417 100644 --- a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/BeanFactoryAwareFunctionRegistry.java +++ b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/BeanFactoryAwareFunctionRegistry.java @@ -516,25 +516,31 @@ public class BeanFactoryAwareFunctionRegistry else { // this needs revisiting as the type is not always Class (think really complex types) Type rawType = FunctionTypeUtils.unwrapActualTypeByIndex(type, 0); - if (!(rawType instanceof Class) && rawType instanceof ParameterizedType) { + if (/*!(rawType instanceof Class) && */rawType instanceof ParameterizedType) { rawType = ((ParameterizedType) rawType).getRawType(); } if (value instanceof Message) { // see AWS adapter with Optional payload - if (!(((Message) value).getPayload() instanceof Optional)) { + if (messageNeedsConversion(rawType, (Message) value)) { convertedValue = messageConverter.fromMessage((Message) value, (Class) rawType, type); if (FunctionTypeUtils.isMessage(type)) { convertedValue = MessageBuilder.withPayload(convertedValue).copyHeaders(((Message) value).getHeaders()).build(); } } - } - else { - if (rawType instanceof Class) { // see AWS adapter with WildardTypeImpl and Azure with Voids - convertedValue = conversionService.convert(value, (Class) rawType); + else if (!FunctionTypeUtils.isMessage(type)) { + convertedValue = ((Message) convertedValue).getPayload(); } } + else if (rawType instanceof Class) { // see AWS adapter with WildardTypeImpl and Azure with Voids + convertedValue = conversionService.convert(value, (Class) rawType); + } } return convertedValue; } + private boolean messageNeedsConversion(Type rawType, Message message) { + return rawType instanceof Class + && !(message.getPayload() instanceof Optional) + && !(message.getPayload().getClass().isAssignableFrom(((Class) rawType))); + } } }