diff --git a/gson/GSON 2.0 NOTES.txt b/gson/GSON 2.0 NOTES.txt index 1896c8ec..7f8e843f 100644 --- a/gson/GSON 2.0 NOTES.txt +++ b/gson/GSON 2.0 NOTES.txt @@ -66,4 +66,15 @@ GSON 1.x creates the empty string "" if the only element is skipped GSON 2.x writes "null" if the only element is skipped com.google.gson.functional.ObjectTest.testAnonymousLocalClassesSerialization com.google.gson.functional.FieldExclusionTest.testInnerClassExclusion -com.google.gson.functional.VersioningTest.testIgnoreLaterVersionClassSerialization \ No newline at end of file +com.google.gson.functional.VersioningTest.testIgnoreLaterVersionClassSerialization + + +GSON 1.x permits duplicate map keys. +GSON 2.x rejects duplicate map keys. +com.google.gson.functional.MapTest.testMapDeserializationWithDuplicateKeys + + +GSON 1.x doesn't serialize subclass fields in collections +GSON 2.x does serialize subclass fields in collections +com.google.gson.functional.InheritanceTest.testClassWithBaseCollectionFieldSerialization +com.google.gson.functional.MoreSpecificTypeSerializationTest.testListOfSubclassFields \ No newline at end of file diff --git a/gson/src/test/java/com/google/gson/functional/MapTest.java b/gson/src/test/java/com/google/gson/functional/MapTest.java index 071e1c4d..530bc9bd 100755 --- a/gson/src/test/java/com/google/gson/functional/MapTest.java +++ b/gson/src/test/java/com/google/gson/functional/MapTest.java @@ -25,6 +25,7 @@ import com.google.gson.JsonParseException; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; +import com.google.gson.JsonSyntaxException; import com.google.gson.common.TestTypes; import com.google.gson.internal.$Gson$Types; import com.google.gson.reflect.TypeToken; @@ -424,8 +425,8 @@ public class MapTest extends TestCase { public void testGeneralMapField() throws Exception { MapWithGeneralMapParameters map = new MapWithGeneralMapParameters(); map.map.put("string", "testString"); - map.map.put("stringArray", new String[] { "one", "two" }); - map.map.put("objectArray", new Object[] { 1, 2L, "three" }); + map.map.put("stringArray", new String[]{"one", "two"}); + map.map.put("objectArray", new Object[]{1, 2L, "three"}); String expected = "{\"map\":{\"string\":\"testString\",\"stringArray\":" + "[\"one\",\"two\"],\"objectArray\":[1,2,\"three\"]}}"; @@ -479,6 +480,14 @@ public class MapTest extends TestCase { assertEquals(map, gson.fromJson(json, new TypeToken>() {}.getType())); } + public void testMapDeserializationWithDuplicateKeys() { + try { + gson.fromJson("{'a':1,'a':2}", new TypeToken>() {}.getType()); + fail(); + } catch (JsonSyntaxException expected) { + } + } + static class Point { private final int x; private final int y;