From 54d65c1c740f9cd498ee16f4d6f3e97a0108dc3d Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Tue, 27 Oct 2020 13:33:11 +0100 Subject: [PATCH] Fix type resolution for wild card types --- .../context/catalog/FunctionTypeUtils.java | 9 +++++++-- .../context/catalog/SimpleFunctionRegistry.java | 16 ++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/FunctionTypeUtils.java b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/FunctionTypeUtils.java index af8027a38..5e0b9be51 100644 --- a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/FunctionTypeUtils.java +++ b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/FunctionTypeUtils.java @@ -92,11 +92,16 @@ public final class FunctionTypeUtils { if (isMessage(type)) { type = getImmediateGenericType(type, 0); } - return type; + return TypeResolver.reify(type); } + /** + * Effectively converts {@link Type} which could be {@link ParameterizedType} to raw Class (no generics). + * @param type actual {@link Type} instance + * @return instance of {@link Class} as raw representation of the provided {@link Type} + */ public static Class getRawType(Type type) { - return type != null ? TypeResolver.resolveRawClass(type, null) : null; + return type != null ? TypeResolver.resolveRawClass(TypeResolver.reify(type), null) : null; } /** 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 23d10a3a3..a070038ff 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 @@ -36,7 +36,6 @@ import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; -import net.jodah.typetools.TypeResolver; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.reactivestreams.Publisher; @@ -372,11 +371,11 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect } public Class getRawOutputType() { - return this.outputType == null ? null : TypeResolver.resolveRawClass(this.outputType, null); + return this.outputType == null ? null : FunctionTypeUtils.getRawType(this.outputType); } public Class getRawInputType() { - return this.inputType == null ? null : TypeResolver.resolveRawClass(this.inputType, null); + return this.inputType == null ? null : FunctionTypeUtils.getRawType(this.inputType); } /** @@ -541,7 +540,9 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect * */ private Class getRawClassFor(@Nullable Type type) { - return type instanceof TypeVariable || type instanceof WildcardType ? Object.class : TypeResolver.resolveRawClass(type, null); + return type instanceof TypeVariable || type instanceof WildcardType + ? Object.class + : FunctionTypeUtils.getRawType(type); } /** @@ -843,7 +844,7 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect private Object convertNonMessageInputIfNecessary(Type inputType, Object input) { Object convertedInput = input; Class rawInputType = this.isTypePublisher(inputType) || this.isInputTypeMessage() - ? TypeResolver.resolveRawClass(FunctionTypeUtils.getImmediateGenericType(inputType, 0), null) + ? FunctionTypeUtils.getRawType(FunctionTypeUtils.getGenericType(inputType)) : this.getRawClassFor(inputType); if (JsonMapper.isJsonString(input) && !Message.class.isAssignableFrom(rawInputType)) { @@ -878,7 +879,7 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect */ private Type extractActualValueTypeIfNecessary(Type type) { if (type instanceof ParameterizedType && (FunctionTypeUtils.isPublisher(type) || FunctionTypeUtils.isMessage(type))) { - return FunctionTypeUtils.getImmediateGenericType(type, 0); + return FunctionTypeUtils.getGenericType(type); } return type; } @@ -903,12 +904,11 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect Object convertedInput = message; type = this.extractActualValueTypeIfNecessary(type); - Class rawType = TypeResolver.resolveRawClass(type, null); + Class rawType = FunctionTypeUtils.getRawType(type); convertedInput = this.isConversionHintRequired(type, rawType) ? SimpleFunctionRegistry.this.messageConverter.fromMessage(message, rawType, type) : SimpleFunctionRegistry.this.messageConverter.fromMessage(message, rawType); - if (this.isInputTypeMessage()) { if (convertedInput == null) { /*