Fix FunctionTypeUtils outout type logic for Supplier
This commit is contained in:
@@ -281,18 +281,18 @@ public final class FunctionTypeUtils {
|
||||
logger.debug("Consumer does not have output type, returning null as output type.");
|
||||
return null;
|
||||
}
|
||||
Type inputType;
|
||||
Type outputType;
|
||||
if (functionType instanceof Class) {
|
||||
functionType = Function.class.isAssignableFrom((Class<?>) functionType)
|
||||
? TypeResolver.reify(Function.class, (Class<Function<?, ?>>) functionType)
|
||||
: TypeResolver.reify(Function.class, (Class<Supplier<?>>) functionType);
|
||||
: TypeResolver.reify(Supplier.class, (Class<Supplier<?>>) functionType);
|
||||
}
|
||||
|
||||
inputType = functionType instanceof ParameterizedType
|
||||
outputType = functionType instanceof ParameterizedType
|
||||
? (isSupplier(functionType) ? ((ParameterizedType) functionType).getActualTypeArguments()[0] : ((ParameterizedType) functionType).getActualTypeArguments()[1])
|
||||
: Object.class;
|
||||
|
||||
return inputType;
|
||||
return outputType;
|
||||
}
|
||||
|
||||
public static Type getImmediateGenericType(Type type, int index) {
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
@@ -412,6 +412,17 @@ public class SimpleFunctionRegistryTests {
|
||||
assertThat(message.getHeaders().get("original")).isEqualTo("newValue");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReactiveMonoSupplier() {
|
||||
FunctionRegistration<ReactiveMonoGreeter> registration = new FunctionRegistration<>(new ReactiveMonoGreeter(),
|
||||
"greeter").type(FunctionType.of(ReactiveMonoGreeter.class));
|
||||
SimpleFunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
catalog.register(registration);
|
||||
FunctionInvocationWrapper function = catalog.lookup("greeter");
|
||||
assertThat(FunctionTypeUtils.isMono(function.getOutputType()));
|
||||
}
|
||||
|
||||
|
||||
public Function<String, String> uppercase() {
|
||||
return v -> v.toUpperCase();
|
||||
@@ -576,6 +587,15 @@ public class SimpleFunctionRegistryTests {
|
||||
}
|
||||
}
|
||||
|
||||
private static class ReactiveMonoGreeter implements Supplier<Mono<Message<String>>> {
|
||||
|
||||
@Override
|
||||
public Mono<Message<String>> get() {
|
||||
return Mono.just(MessageBuilder.withPayload("hello").build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class HeaderEnricherFunction implements Function<Message<?>, Message<?>> {
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user