From 15c2ae7548317a9b21926b63fc4c192a65258e22 Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Sun, 11 Mar 2012 21:37:13 +0000 Subject: [PATCH] Updated map subclass deserialization test to illustrate a failing condition. Gson currently uses LinkedHashMap for an instance if a Map subclass does not define a default constructor. --- .../test/java/com/google/gson/functional/MapTest.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 fce325a0..ff3a7e04 100755 --- a/gson/src/test/java/com/google/gson/functional/MapTest.java +++ b/gson/src/test/java/com/google/gson/functional/MapTest.java @@ -157,7 +157,7 @@ public class MapTest extends TestCase { } public void testParameterizedMapSubclassSerialization() { - MyParameterizedMap map = new MyParameterizedMap(); + MyParameterizedMap map = new MyParameterizedMap(10); map.put("a", "b"); Type type = new TypeToken>() {}.getType(); String json = gson.toJson(map, type); @@ -172,11 +172,12 @@ public class MapTest extends TestCase { assertEquals(2, map.get("b").intValue()); } + @SuppressWarnings({ "unused", "serial" }) private static class MyParameterizedMap extends LinkedHashMap { - private static final long serialVersionUID = 1L; - - @SuppressWarnings("unused") - int foo = 10; + final int foo; + MyParameterizedMap(int foo) { + this.foo = foo; + } } public void testMapSubclassSerialization() {