diff --git a/gson/src/main/java/com/google/gson/internal/$Gson$Types.java b/gson/src/main/java/com/google/gson/internal/$Gson$Types.java index f66ac157b1..adea605f59 100644 --- a/gson/src/main/java/com/google/gson/internal/$Gson$Types.java +++ b/gson/src/main/java/com/google/gson/internal/$Gson$Types.java @@ -275,6 +275,10 @@ static Type getGenericSupertype(Type context, Class rawType, Class toResol * @param supertype a superclass of, or interface implemented by, this. */ static Type getSupertype(Type context, Class contextRawType, Class supertype) { + if (context instanceof WildcardType) { + // wildcards are useless for resolving supertypes. As the upper bound has the same raw type, use it instead + context = ((WildcardType)context).getUpperBounds()[0]; + } checkArgument(supertype.isAssignableFrom(contextRawType)); return resolve(context, contextRawType, $Gson$Types.getGenericSupertype(context, contextRawType, supertype)); diff --git a/gson/src/test/java/com/google/gson/functional/CollectionTest.java b/gson/src/test/java/com/google/gson/functional/CollectionTest.java index 9a8f707b4f..0584cb63ef 100644 --- a/gson/src/test/java/com/google/gson/functional/CollectionTest.java +++ b/gson/src/test/java/com/google/gson/functional/CollectionTest.java @@ -393,4 +393,23 @@ public void testSetDeserialization() { assertTrue(entry.value == 1 || entry.value == 2); } } + + class BigClass { Map> inBig; } + + class SmallClass { String inSmall; } + + public void testIssue1107() { + String json = "{\n" + + " \"inBig\": {\n" + + " \"key\": [\n" + + " { \"inSmall\": \"hello\" }\n" + + " ]\n" + + " }\n" + + "}"; + BigClass bigClass = new Gson().fromJson(json, BigClass.class); + SmallClass small = bigClass.inBig.get("key").get(0); + assertNotNull(small); + assertEquals("hello", small.inSmall); + } + }