Deserialzing works in gson-2.1 but not gson-2.4.4

I have this snippet:

HashMap<String, List<ClassOne>> mappingMap = new HashMap<String, List<ClassOne>>();
String key = "pop";
ClassOne c1 = new ClassOne();
ArrayList<ClassOne> al = new ArrayList<ClassOne>();
mappingMap.put(key, al);
Gson gson = new Gson();
String data = gson.toJson(mappingMap);
HashMap<String, List<ClassOne>> dmm = gson.fromJson(data, new TypeToken<Map<String, List<ClassOne>>>() {}.getType());

It when run with the gson-2.1.jar , it works fine. When run with the gson-2.2.4.jar I get the following exception

java.lang.ClassCastException: cannot be cast to java.util.HashMap at com......

Wondering if anyone could explain, or point out what I am doing incorrectly.


I don't know about 2.1, but if it's true that it worked, then Gson must have changed their default Map implementation to use when deserializing Map types from HashMap to LinkedTreeMap in gson-2.2.4.

If you want to continue using HashMap, specify it in the TypeToken.

new TypeToken<HashMap<String, List<ClassOne>>>()

Need Your Help

Introducing delay while ajax call in select2 plugin

javascript jquery delay jquery-select2

I am using select 2 example from

How do you test dependency interaction

c# dependency-injection mocking tdd

I have a class that manipulates dependencies based on other dependency results: