Open GoogleCodeExporter opened 9 years ago
You need to use a TypeToken as per
https://sites.google.com/site/gson/gson-user-guide#TOC-Serializing-and-Deseriali
zing-Generic-Types.
Code below:
public static class TestMetadata<R extends TestResource>
{
private R resource;
}
public static class TestResource
{
private int id;
}
@Test
public void testNarrowing()
{
TestMetadata metadata = new com.google.gson.GsonBuilder().create().fromJson("{ 'resource':{ 'id':17 }}", new TypeToken<TestMetadata<TestResource>>(){}.getType());
Assert.assertEquals("id", 17, metadata.resource.id);
}
Original comment by Tobias1...@gmail.com
on 17 Jun 2014 at 9:53
Original issue reported on code.google.com by
robertwi...@gmail.com
on 28 Apr 2014 at 10:37