From a0afec71fff2e36827e83351bded4b4aae281b87 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Sat, 11 Feb 2012 18:19:54 +0000 Subject: [PATCH] Test case to demonstrate no such crash as reported in issue 408. --- .../com/google/gson/functional/MapTest.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) 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 6065ca06..fce325a0 100755 --- a/gson/src/test/java/com/google/gson/functional/MapTest.java +++ b/gson/src/test/java/com/google/gson/functional/MapTest.java @@ -490,7 +490,32 @@ public class MapTest extends TestCase { } catch (JsonSyntaxException expected) { } } - + + public void testSerializeMapOfMaps() { + Type type = new TypeToken>>() {}.getType(); + Map> map = newMap( + "a", newMap("ka1", "va1", "ka2", "va2"), + "b", newMap("kb1", "vb1", "kb2", "vb2")); + assertEquals("{'a':{'ka1':'va1','ka2':'va2'},'b':{'kb1':'vb1','kb2':'vb2'}}", + gson.toJson(map, type).replace('"', '\'')); + } + + public void testDeerializeMapOfMaps() { + Type type = new TypeToken>>() {}.getType(); + Map> map = newMap( + "a", newMap("ka1", "va1", "ka2", "va2"), + "b", newMap("kb1", "vb1", "kb2", "vb2")); + String json = "{'a':{'ka1':'va1','ka2':'va2'},'b':{'kb1':'vb1','kb2':'vb2'}}"; + assertEquals(map, gson.fromJson(json, type)); + } + + private Map newMap(K key1, V value1, K key2, V value2) { + Map result = new LinkedHashMap(); + result.put(key1, value1); + result.put(key2, value2); + return result; + } + public void testMapNamePromotionWithJsonElementReader() { String json = "{'2.3':'a'}"; Map map = new LinkedHashMap();