diff --git a/src/main/java/org/springframework/data/util/TypeDiscoverer.java b/src/main/java/org/springframework/data/util/TypeDiscoverer.java index ed76d1f9a..cbe4e209e 100644 --- a/src/main/java/org/springframework/data/util/TypeDiscoverer.java +++ b/src/main/java/org/springframework/data/util/TypeDiscoverer.java @@ -100,10 +100,21 @@ class TypeDiscoverer implements TypeInformation { return new ClassTypeInformation((Class) fieldType); } - Map variableMap = GenericTypeResolver.getTypeVariableMap(resolveType(fieldType)); + Class resolveType = resolveType(fieldType); + Map variableMap = new HashMap(); + variableMap.putAll(GenericTypeResolver.getTypeVariableMap(resolveType)); if (fieldType instanceof ParameterizedType) { + ParameterizedType parameterizedType = (ParameterizedType) fieldType; + + TypeVariable>[] typeParameters = resolveType.getTypeParameters(); + Type[] arguments = parameterizedType.getActualTypeArguments(); + + for (int i = 0; i < typeParameters.length; i++) { + variableMap.put(typeParameters[i], arguments[i]); + } + return new ParameterizedTypeInformation(parameterizedType, this, variableMap); } diff --git a/src/test/java/org/springframework/data/util/ParameterizedTypeUnitTests.java b/src/test/java/org/springframework/data/util/ParameterizedTypeUnitTests.java index 1eae5bd99..5d3f67106 100644 --- a/src/test/java/org/springframework/data/util/ParameterizedTypeUnitTests.java +++ b/src/test/java/org/springframework/data/util/ParameterizedTypeUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2014 the original author or authors. + * Copyright 2011-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; @@ -125,6 +126,17 @@ public class ParameterizedTypeUnitTests { assertThat(type.getActualType(), is(type)); } + /** + * @see DATACMNS-697 + */ + @Test + public void usesLocalGenericInformationOfFields() { + + TypeInformation information = ClassTypeInformation.from(NormalizedProfile.class); + TypeInformation valueType = information.getProperty("education2.data").getComponentType(); + assertThat(valueType.getProperty("value").getType(), is(typeCompatibleWith(Education.class))); + } + @SuppressWarnings("serial") class Localized extends HashMap { S value; @@ -151,4 +163,21 @@ public class ParameterizedTypeUnitTests { class Second { Parameterized property; } + + // see DATACMNS-697 + + class NormalizedProfile { + + ListField education2; + } + + class ListField { + List> data; + } + + class Value { + T value; + } + + class Education {} }