|
17 | 17 |
|
18 | 18 | import java.lang.reflect.Constructor;
|
19 | 19 | import java.lang.reflect.Method;
|
| 20 | +import java.lang.reflect.TypeVariable; |
20 | 21 | import java.util.Collection;
|
21 | 22 | import java.util.List;
|
22 | 23 | import java.util.Map;
|
23 | 24 | import java.util.Set;
|
24 | 25 |
|
| 26 | +import org.springframework.core.MethodParameter; |
25 | 27 | import org.springframework.core.ResolvableType;
|
26 | 28 | import org.springframework.core.convert.TypeDescriptor;
|
27 | 29 | import org.springframework.lang.Nullable;
|
@@ -61,9 +63,11 @@ public static TypeInformation<?> of(ResolvableType type) {
|
61 | 63 |
|
62 | 64 | Assert.notNull(type, "Type must not be null");
|
63 | 65 |
|
64 |
| - return type.hasGenerics() || (type.isArray() && type.getComponentType().hasGenerics()) // |
65 |
| - ? TypeDiscoverer.td(type) |
66 |
| - : ClassTypeInformation.cti(type); |
| 66 | + return type.hasGenerics() |
| 67 | + || (type.isArray() && type.getComponentType().hasGenerics()) // |
| 68 | + || (type.getType() instanceof TypeVariable) |
| 69 | + ? TypeDiscoverer.td(type) |
| 70 | + : ClassTypeInformation.cti(type); |
67 | 71 | }
|
68 | 72 |
|
69 | 73 | /**
|
@@ -103,7 +107,23 @@ public static TypeInformation<?> fromReturnTypeOf(Method method) {
|
103 | 107 | * @since 3.0
|
104 | 108 | */
|
105 | 109 | public static TypeInformation<?> fromReturnTypeOf(Method method, @Nullable Class<?> type) {
|
106 |
| - return ClassTypeInformation.fromReturnTypeOf(method, type); |
| 110 | + |
| 111 | + ResolvableType intermediate = type == null |
| 112 | + ? ResolvableType.forMethodReturnType(method) |
| 113 | + : ResolvableType.forMethodReturnType(method, type); |
| 114 | + |
| 115 | + return TypeInformation.of(intermediate); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Returns a new {@link TypeInformation} for the given {@link MethodParameter}. |
| 120 | + * |
| 121 | + * @param parameter must not be {@literal null}. |
| 122 | + * @return will never be {@literal null}. |
| 123 | + * @since 3.0 |
| 124 | + */ |
| 125 | + public static TypeInformation<?> fromMethodParameter(MethodParameter parameter) { |
| 126 | + return TypeInformation.of(ResolvableType.forMethodParameter(parameter)); |
107 | 127 | }
|
108 | 128 |
|
109 | 129 | /**
|
|
0 commit comments