From 066b1545085f375080f64b5fcdea4d081405e197 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Thu, 10 Dec 2020 07:56:15 +0100 Subject: [PATCH] interim --- .../catalog/SimpleFunctionRegistry.java | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/SimpleFunctionRegistry.java b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/SimpleFunctionRegistry.java index 5fc1814a2..b66c224f6 100644 --- a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/SimpleFunctionRegistry.java +++ b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/SimpleFunctionRegistry.java @@ -981,8 +981,8 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect /* * */ - private boolean isConversionHintRequired(Object actualType, Class rawType) { - return rawType != actualType; + private boolean isConversionHintRequired(Type actualType, Class rawType) { + return rawType != actualType; // && !FunctionTypeUtils.isMessage(actualType); } /* @@ -1003,14 +1003,28 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect } } - Object convertedInput = message; - type = this.extractActualValueTypeIfNecessary(type); - Class rawType = FunctionTypeUtils.getRawType(type); - convertedInput = this.isConversionHintRequired(type, rawType) - ? SimpleFunctionRegistry.this.messageConverter.fromMessage(message, rawType, type) - : SimpleFunctionRegistry.this.messageConverter.fromMessage(message, rawType); + Object convertedInput = message.getPayload(); - if (this.isInputTypeMessage()) { +// if (FunctionTypeUtils.isMessage(type) && FunctionTypeUtils.getRawType(type)) { +// +// } + + + +// type = this.extractActualValueTypeIfNecessary(type); + + Type itemType = this.extractActualValueTypeIfNecessary(type); + Class rawType = FunctionTypeUtils.isMessage(type) + ? FunctionTypeUtils.getRawType(itemType) + : FunctionTypeUtils.getRawType(type); +// if (!rawType.isAssignableFrom(message.getPayload().getClass())) { + convertedInput = this.isConversionHintRequired(type, rawType) + ? SimpleFunctionRegistry.this.messageConverter.fromMessage(message, rawType, itemType) + : SimpleFunctionRegistry.this.messageConverter.fromMessage(message, rawType); +// } + + + if (FunctionTypeUtils.isMessage(type)) { if (convertedInput == null) { /* * In the event conversion was unsuccessful we simply return the original un-converted message. @@ -1099,11 +1113,15 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect else if (FunctionTypeUtils.isFlux(type) && publisher instanceof Mono) { publisher = Flux.from(publisher); } - Type actualType = type != null ? FunctionTypeUtils.getGenericType(type) : type; + Type actualType = type != null && FunctionTypeUtils.isPublisher(type) ? FunctionTypeUtils.getImmediateGenericType(type, 0) : type; +// Type actualType = type != null ? FunctionTypeUtils.getGenericType(type, 0) : type; +// if (actualType == null) { +// actualType = type; +// } return publisher instanceof Mono - ? Mono.from(publisher).map(v -> this.convertInputIfNecessary(v, actualType)) + ? Mono.from(publisher).map(v -> this.convertInputIfNecessary(v, actualType == null ? type : actualType)) .doOnError(ex -> logger.error("Failed to convert input", (Throwable) ex)) - : Flux.from(publisher).map(v -> this.convertInputIfNecessary(v, actualType)) + : Flux.from(publisher).map(v -> this.convertInputIfNecessary(v, actualType == null ? type : actualType)) .doOnError(ex -> logger.error("Failed to convert input", (Throwable) ex)); }