DATACMNS-1139 - AbstractPersistentProperty.getRawType() now correctly resolves generics.

We're now favoring the generic TypeInformation over trying to resolve the property type via field or PropertyDescriptor as only the former does proper generic type resolution.
This commit is contained in:
Oliver Gierke
2017-08-14 14:06:16 +02:00
parent fab854c906
commit fb9d38d79c
2 changed files with 13 additions and 10 deletions

View File

@@ -200,6 +200,14 @@ public class AbstractPersistentPropertyUnitTests {
assertThat(property.getName()).isEqualTo("var_name_with_underscores");
}
@Test // DATACMNS-1139
public void resolvesGenericsForRawType() {
SamplePersistentProperty property = getProperty(FirstConcrete.class, "genericField");
assertThat(property.getRawType()).isEqualTo(String.class);
}
private <T> BasicPersistentEntity<T, SamplePersistentProperty> getEntity(Class<T> type) {
return new BasicPersistentEntity<>(ClassTypeInformation.from(type));
}
@@ -209,11 +217,9 @@ public class AbstractPersistentPropertyUnitTests {
Optional<Field> field = Optional.ofNullable(ReflectionUtils.findField(type, name));
Optional<PropertyDescriptor> descriptor = getPropertyDescriptor(type, name);
Property property = field
.map(it -> descriptor//
.map(foo -> Property.of(it, foo))//
.orElseGet(() -> Property.of(it)))
.orElseGet(() -> getPropertyDescriptor(type, name)//
Property property = field.map(it -> descriptor//
.map(foo -> Property.of(it, foo))//
.orElseGet(() -> Property.of(it))).orElseGet(() -> getPropertyDescriptor(type, name)//
.map(it -> Property.of(it))//
.orElseThrow(
() -> new IllegalArgumentException(String.format("Couldn't find property %s on %s!", name, type))));