Skip to content

Commit

Permalink
DATACMNS-440 - Fixed map value type resolving for Map value types.
Browse files Browse the repository at this point in the history
Previously the map value type resolving algorithm checked the value type to be of type Map again to shortcut the resolution. We now weakened this to an assignment check and eagerly resolve the generic type if its bound on exactly that level already. If no concrete type argument can be found, we fall back to the general generics resolution mechanism.
  • Loading branch information
odrotbohm committed Feb 13, 2014
1 parent 2084680 commit 931a697
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Expand Up @@ -56,9 +56,13 @@ public ParameterizedTypeInformation(ParameterizedType type, TypeDiscoverer<?> pa
@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();
Expand Down
Expand Up @@ -25,6 +25,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;

import org.hamcrest.Matchers;
import org.junit.Test;
Expand Down Expand Up @@ -296,6 +297,26 @@ public void returnsNullForRawTypesOnly() {
assertThat(from(MyIterable.class).getComponentType(), is(notNullValue()));
}

/**
* @see DATACMNS-440
*/
@Test
public void detectsSpecialMapAsMapValueType() {

TypeInformation<SuperGenerics> 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<String> {

}
Expand Down Expand Up @@ -425,4 +446,9 @@ interface Identifiable {
interface MyRawIterable extends Iterable {}

interface MyIterable<T> extends Iterable<T> {}

static class SuperGenerics {

SortedMap<String, ? extends SortedMap<String, List<Person>>> seriously;
}
}

0 comments on commit 931a697

Please sign in to comment.