Skip to content
Permalink
Browse files

fix issue #1107: resolve element type in wildcard collection types (#…

…1146)

* fix issue #1107: resolve element type in wildcard collection types

* fix Codacy warnings

* fix Codacy warnings
  • Loading branch information...
amogilev authored and inder123 committed Sep 22, 2017
1 parent 08bbb22 commit b1fb9ca9a1bea5440bc6a5b506ccf67236b08243
@@ -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));
@@ -393,4 +393,23 @@ public void testSetDeserialization() {
assertTrue(entry.value == 1 || entry.value == 2);
}
}

private class BigClass { private Map<String, ? extends List<SmallClass>> inBig; }

private class SmallClass { private 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);
}

}

0 comments on commit b1fb9ca

Please sign in to comment.
You can’t perform that action at this time.