Fix type resolution for wild card types
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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) {
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user