google / google/gson

Deserialization of parameterized types throws an IllegalArgumentException

Open
#576 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
24.2k
Forks
4.5k
Avg merge
6d 4h
Merged PRs (30d)
12

Description

```
The following simple test case throws an IllegalArgumentException

public static class TestMetadata
{
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 TestMetadata().getClass());

Assert.assertEquals("id", 17, metadata.resource.id);
}

I get the following exception: java.lang.IllegalArgumentException: Can not set
com.ancestry.academy.test.unit.gson.GsonVanillaTest$TestResource field
com.ancestry.academy.test.unit.gson.GsonVanillaTest$TestMetadata.

Version 2.2.4 on Mac OSX

```

Original issue reported on code.google.com by `robertwi...@gmail.com` on 28 Apr 2014 at 10:37

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.