diff --git a/src/main/java/org/springframework/data/util/TypeDiscoverer.java b/src/main/java/org/springframework/data/util/TypeDiscoverer.java index 0ee9e0b2d..2a8e59c72 100644 --- a/src/main/java/org/springframework/data/util/TypeDiscoverer.java +++ b/src/main/java/org/springframework/data/util/TypeDiscoverer.java @@ -198,9 +198,37 @@ class TypeDiscoverer implements TypeInformation { return createInfo(field.getGenericType()); } + PropertyDescriptor descriptor = findPropertyDescriptor(type, fieldname); + return descriptor == null ? null : createInfo(getGenericType(descriptor)); + } + + /** + * Finds the {@link PropertyDescriptor} for the property with the given name on the given type. + * + * @param type must not be {@literal null}. + * @param fieldname must not be {@literal null} or empty. + * @return + */ + private static PropertyDescriptor findPropertyDescriptor(Class type, String fieldname) { + PropertyDescriptor descriptor = BeanUtils.getPropertyDescriptor(type, fieldname); - return descriptor == null ? null : createInfo(getGenericType(descriptor)); + if (descriptor != null) { + return descriptor; + } + + List> superTypes = new ArrayList>(); + superTypes.addAll(Arrays.asList(type.getInterfaces())); + superTypes.add(type.getSuperclass()); + + for (Class interfaceType : type.getInterfaces()) { + descriptor = findPropertyDescriptor(interfaceType, fieldname); + if (descriptor != null) { + return descriptor; + } + } + + return null; } /** diff --git a/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java b/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java index 032d66162..139941a26 100644 --- a/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java +++ b/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java @@ -394,8 +394,11 @@ public class ClassTypeInformationUnitTests { Category getCategory(); } - interface Category { + interface Category extends Identifiable { + } + + interface Identifiable { Long getId(); } }