Tests to illustrate differences between GSON 1.7 and 2.0
This commit is contained in:
parent
0340e01f98
commit
c226bd4f3f
@ -67,3 +67,14 @@ 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
|
||||
|
||||
|
||||
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
|
@ -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<Map<Boolean, String>>() {}.getType()));
|
||||
}
|
||||
|
||||
public void testMapDeserializationWithDuplicateKeys() {
|
||||
try {
|
||||
gson.fromJson("{'a':1,'a':2}", new TypeToken<Map<String, Integer>>() {}.getType());
|
||||
fail();
|
||||
} catch (JsonSyntaxException expected) {
|
||||
}
|
||||
}
|
||||
|
||||
static class Point {
|
||||
private final int x;
|
||||
private final int y;
|
||||
|
Loading…
Reference in New Issue
Block a user