diff --git a/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java b/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java index c466c275f..42d750ae7 100644 --- a/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java +++ b/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java @@ -56,9 +56,13 @@ class ParameterizedTypeInformation extends ParentTypeAwareTypeInformation @SuppressWarnings("deprecation") public TypeInformation getMapValueType() { - if (Map.class.equals(getType())) { + if (Map.class.isAssignableFrom(getType())) { + Type[] arguments = type.getActualTypeArguments(); - return createInfo(arguments[1]); + + if (arguments.length > 1) { + return createInfo(arguments[1]); + } } Class rawType = getType(); diff --git a/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java b/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java index 9975d097f..e9b87faf5 100644 --- a/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java +++ b/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java @@ -25,6 +25,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.SortedMap; import org.hamcrest.Matchers; import org.junit.Test; @@ -296,6 +297,26 @@ public class ClassTypeInformationUnitTests { assertThat(from(MyIterable.class).getComponentType(), is(notNullValue())); } + /** + * @see DATACMNS-440 + */ + @Test + public void detectsSpecialMapAsMapValueType() { + + TypeInformation information = ClassTypeInformation.from(SuperGenerics.class); + + TypeInformation propertyInformation = information.getProperty("seriously"); + assertThat(propertyInformation.getType(), is((Object) SortedMap.class)); + + TypeInformation mapValueType = propertyInformation.getMapValueType(); + assertThat(mapValueType.getType(), is((Object) SortedMap.class)); + assertThat(mapValueType.getComponentType().getType(), is((Object) String.class)); + + TypeInformation nestedValueType = mapValueType.getMapValueType(); + assertThat(nestedValueType.getType(), is((Object) List.class)); + assertThat(nestedValueType.getComponentType().getType(), is((Object) Person.class)); + } + static class StringMapContainer extends MapContainer { } @@ -425,4 +446,9 @@ public class ClassTypeInformationUnitTests { interface MyRawIterable extends Iterable {} interface MyIterable extends Iterable {} + + static class SuperGenerics { + + SortedMap>> seriously; + } }