DATACMNS-1138 - TypeInformation.specialize(…) now only specializes unresolved parameterized types.
Type specialization - i.e. enrichment of a raw type with a current generic context - is now only done if the current type is not yet resolved completely. This allows wildcarded target references to just fall back to the type to specialize, which will then by definition carry more generics information than the one to be specialized.
This commit is contained in:
@@ -181,6 +181,15 @@ class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T>
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.util.TypeDiscoverer#specialize(org.springframework.data.util.ClassTypeInformation)
|
||||
*/
|
||||
@Override
|
||||
public TypeInformation<?> specialize(ClassTypeInformation<?> type) {
|
||||
return isResolvedCompletely() ? type : super.specialize(type);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.util.ParentTypeAwareTypeInformation#equals(java.lang.Object)
|
||||
*/
|
||||
|
||||
@@ -106,7 +106,7 @@ public class ClassTypeInformationUnitTests {
|
||||
|
||||
property = information.getProperty("rawSet");
|
||||
assertEquals(Set.class, property.getType());
|
||||
assertThat(property.getComponentType().getType(), is(Matchers.<Class<?>>equalTo(Object.class)));
|
||||
assertThat(property.getComponentType().getType(), is(Matchers.<Class<?>> equalTo(Object.class)));
|
||||
assertNull(property.getMapValueType());
|
||||
}
|
||||
|
||||
@@ -413,6 +413,18 @@ public class ClassTypeInformationUnitTests {
|
||||
assertThat(information.getProperty("field").getType(), is(typeCompatibleWith(Nested.class)));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1138
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void usesTargetTypeForWildcardedBaseOnSpecialization() {
|
||||
|
||||
ClassTypeInformation<WildcardedWrapper> wrapper = ClassTypeInformation.from(WildcardedWrapper.class);
|
||||
ClassTypeInformation<SomeConcrete> concrete = ClassTypeInformation.from(SomeConcrete.class);
|
||||
|
||||
TypeInformation<?> property = wrapper.getProperty("wildcarded");
|
||||
|
||||
assertThat(property.specialize(concrete), is((TypeInformation) concrete));
|
||||
}
|
||||
|
||||
static class StringMapContainer extends MapContainer<String> {
|
||||
|
||||
}
|
||||
@@ -611,4 +623,16 @@ public class ClassTypeInformationUnitTests {
|
||||
static class Nested extends SomeType<String> {}
|
||||
|
||||
static class Concrete extends SomeType<Nested> {}
|
||||
|
||||
// DATACMNS-1138
|
||||
|
||||
static class SomeGeneric<T> {
|
||||
T value;
|
||||
}
|
||||
|
||||
static class SomeConcrete extends SomeGeneric<String> {}
|
||||
|
||||
static class WildcardedWrapper {
|
||||
SomeGeneric<?> wildcarded;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user