diff --git a/src/main/java/org/springframework/data/util/TypeDiscoverer.java b/src/main/java/org/springframework/data/util/TypeDiscoverer.java index 8ef54480a..470d7a6da 100644 --- a/src/main/java/org/springframework/data/util/TypeDiscoverer.java +++ b/src/main/java/org/springframework/data/util/TypeDiscoverer.java @@ -89,7 +89,7 @@ class TypeDiscoverer implements TypeInformation { this.componentType = Lazy.of(this::doGetComponentType); this.valueType = Lazy.of(this::doGetMapValueType); this.typeVariableMap = typeVariableMap; - this.hashCode = 17 + (31 * type.hashCode()) + (31 * typeVariableMap.hashCode()); + this.hashCode = 17 + 31 * type.hashCode() + 31 * typeVariableMap.hashCode(); } /** @@ -435,11 +435,12 @@ class TypeDiscoverer implements TypeInformation { } List candidates = new ArrayList<>(); - Type genericSuperclass = rawType.getGenericSuperclass(); + if (genericSuperclass != null) { candidates.add(genericSuperclass); } + candidates.addAll(Arrays.asList(rawType.getGenericInterfaces())); for (Type candidate : candidates) { @@ -449,7 +450,9 @@ class TypeDiscoverer implements TypeInformation { if (superType.equals(candidateInfo.getType())) { return candidateInfo; } else { + TypeInformation nestedSuperType = candidateInfo.getSuperTypeInformation(superType); + if (nestedSuperType != null) { return nestedSuperType; } @@ -501,17 +504,19 @@ class TypeDiscoverer implements TypeInformation { Class[] arguments = GenericTypeResolver.resolveTypeArguments(getType(), bound); - if (arguments == null) { - return getSuperTypeInformation(bound) instanceof ParameterizedTypeInformation ? ClassTypeInformation.OBJECT - : null; + if (arguments != null) { + return createInfo(arguments[index]); } - return createInfo(arguments[index]); + return getSuperTypeInformation(bound) instanceof ParameterizedTypeInformation // + ? ClassTypeInformation.OBJECT // + : null; } private Class getBaseType(Class[] candidates) { Class type = getType(); + for (Class candidate : candidates) { if (candidate.isAssignableFrom(type)) { return candidate;