Test case to demonstrate no such crash as reported in issue 408.
This commit is contained in:
parent
2e6b22fa2e
commit
a0afec71ff
@ -490,7 +490,32 @@ public class MapTest extends TestCase {
|
||||
} catch (JsonSyntaxException expected) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testSerializeMapOfMaps() {
|
||||
Type type = new TypeToken<Map<String, Map<String, String>>>() {}.getType();
|
||||
Map<String, Map<String, String>> 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<Map<String, Map<String, String>>>() {}.getType();
|
||||
Map<String, Map<String, String>> 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 <K, V> Map<K, V> newMap(K key1, V value1, K key2, V value2) {
|
||||
Map<K, V> result = new LinkedHashMap<K, V>();
|
||||
result.put(key1, value1);
|
||||
result.put(key2, value2);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void testMapNamePromotionWithJsonElementReader() {
|
||||
String json = "{'2.3':'a'}";
|
||||
Map<Double, String> map = new LinkedHashMap<Double, String>();
|
||||
|
Loading…
Reference in New Issue
Block a user