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.
This commit is contained in:
parent
4c629347da
commit
15c2ae7548
@ -157,7 +157,7 @@ public class MapTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testParameterizedMapSubclassSerialization() {
|
public void testParameterizedMapSubclassSerialization() {
|
||||||
MyParameterizedMap<String, String> map = new MyParameterizedMap<String, String>();
|
MyParameterizedMap<String, String> map = new MyParameterizedMap<String, String>(10);
|
||||||
map.put("a", "b");
|
map.put("a", "b");
|
||||||
Type type = new TypeToken<MyParameterizedMap<String, String>>() {}.getType();
|
Type type = new TypeToken<MyParameterizedMap<String, String>>() {}.getType();
|
||||||
String json = gson.toJson(map, type);
|
String json = gson.toJson(map, type);
|
||||||
@ -172,11 +172,12 @@ public class MapTest extends TestCase {
|
|||||||
assertEquals(2, map.get("b").intValue());
|
assertEquals(2, map.get("b").intValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "unused", "serial" })
|
||||||
private static class MyParameterizedMap<K, V> extends LinkedHashMap<K, V> {
|
private static class MyParameterizedMap<K, V> extends LinkedHashMap<K, V> {
|
||||||
private static final long serialVersionUID = 1L;
|
final int foo;
|
||||||
|
MyParameterizedMap(int foo) {
|
||||||
@SuppressWarnings("unused")
|
this.foo = foo;
|
||||||
int foo = 10;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMapSubclassSerialization() {
|
public void testMapSubclassSerialization() {
|
||||||
|
Loading…
Reference in New Issue
Block a user