diff --git a/gson/src/test/java/com/google/gson/functional/RawSerializationTest.java b/gson/src/test/java/com/google/gson/functional/RawSerializationTest.java index de0322bf..d5e8883e 100644 --- a/gson/src/test/java/com/google/gson/functional/RawSerializationTest.java +++ b/gson/src/test/java/com/google/gson/functional/RawSerializationTest.java @@ -61,6 +61,28 @@ public class RawSerializationTest extends TestCase { assertEquals(expectedJson, json); } + public void testTwoLevelParameterizedObject() { + Bar> bar = new Bar>(new Bar(new Foo(1))); + String expectedJson = "{\"t\":{\"t\":{\"b\":1}}}"; + // Ensure that serialization works without specifying the type explicitly + String json = gson.toJson(bar); + assertEquals(expectedJson, json); + // Ensure that serialization also works when the type is specified explicitly + json = gson.toJson(bar, new TypeToken>>(){}.getType()); + assertEquals(expectedJson, json); + } + + public void testThreeLevelParameterizedObject() { + Bar>> bar = new Bar>>(new Bar>(new Bar(new Foo(1)))); + String expectedJson = "{\"t\":{\"t\":{\"t\":{\"b\":1}}}}"; + // Ensure that serialization works without specifying the type explicitly + String json = gson.toJson(bar); + assertEquals(expectedJson, json); + // Ensure that serialization also works when the type is specified explicitly + json = gson.toJson(bar, new TypeToken>>>(){}.getType()); + assertEquals(expectedJson, json); + } + private static class Foo { @SuppressWarnings("unused") int b;