Prefer explicitly declared generic parameter over Iterable in TypeDiscoverer.getComponentType().
Related ticket: #2312.
This commit is contained in:
@@ -148,6 +148,12 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
return getTypeArgument(CustomCollections.getMapBaseType(rawType), 0);
|
||||
}
|
||||
|
||||
List<TypeInformation<?>> arguments = getTypeArguments();
|
||||
|
||||
if (arguments.size() > 0) {
|
||||
return arguments.get(0);
|
||||
}
|
||||
|
||||
if (Iterable.class.isAssignableFrom(rawType)) {
|
||||
return getTypeArgument(Iterable.class, 0);
|
||||
}
|
||||
@@ -156,9 +162,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
return getTypeArgument(rawType, 0);
|
||||
}
|
||||
|
||||
List<TypeInformation<?>> arguments = getTypeArguments();
|
||||
|
||||
return arguments.size() > 0 ? arguments.get(0) : null;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.beans.factory.annotation.Autowire;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.data.geo.GeoResults;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
@@ -326,6 +327,14 @@ public class TypeDiscovererUnitTests {
|
||||
assertThat(map.getMapValueType().getType()).isEqualTo(String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void detectsComponentTypeOfTypedClass() {
|
||||
|
||||
TypeInformation<?> property = TypeInformation.of(GeoResultsWrapper.class).getProperty("results");
|
||||
|
||||
assertThat(property.getComponentType().getType()).isEqualTo(Leaf.class);
|
||||
}
|
||||
|
||||
class Person {
|
||||
|
||||
Addresses addresses;
|
||||
@@ -415,4 +424,8 @@ public class TypeDiscovererUnitTests {
|
||||
class EnumMapWrapper {
|
||||
EnumMap<Autowire, String> map;
|
||||
}
|
||||
|
||||
class GeoResultsWrapper {
|
||||
GeoResults<Leaf> results;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user