GH-383 Ensure FunctionType retains ParameterizedType as 'type' filed

Resolves #383
This commit is contained in:
Oleg Zhurakousky
2019-07-03 16:06:41 +02:00
parent e6625394a8
commit 1cf42f95f6
2 changed files with 28 additions and 1 deletions

View File

@@ -32,6 +32,7 @@ import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.messaging.Message;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;
/**
@@ -105,7 +106,14 @@ public class FunctionType {
}
public static FunctionType of(Type function) {
return new FunctionType(function);
FunctionType ft = new FunctionType(function);
if (!ft.isWrapper() && !(ft.type instanceof ParameterizedType)) {
Type[] genericInterfaces = ((Class<?>) function).getGenericInterfaces();
if (!ObjectUtils.isEmpty(genericInterfaces)) {
ft.type = genericInterfaces[0];
}
}
return ft;
}
public static FunctionType from(Class<?> input) {

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.function.context;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.Map;
@@ -25,6 +26,8 @@ import java.util.function.Supplier;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuple3;
import org.springframework.core.ResolvableType;
import org.springframework.messaging.Message;
@@ -38,6 +41,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class FunctionTypeTests {
@Test
public void functionWithTuples() {
FunctionType functionType = FunctionType.of(MyFunction.class);
assertThat(functionType.getType()).isInstanceOf(ParameterizedType.class);
}
@Test
public void plainFunction() {
FunctionType function = new FunctionType(IntegerToString.class);
@@ -324,4 +333,14 @@ public class FunctionTypeTests {
}
private static class MyFunction
implements Function<Tuple2<Flux<String>, Flux<Integer>>, Tuple3<Flux<String>, Flux<Integer>, Flux<Object>>> {
@Override
public Tuple3<Flux<String>, Flux<Integer>, Flux<Object>> apply(Tuple2<Flux<String>, Flux<Integer>> t) {
return null;
}
}
}