Problem
Given a Gson object with format LinkedTreeMap<String, String>
, e.g.:
1 | LinkedTreeMap<String, String> misc = { |
I got the HashMap with
1 | { |
And pass case assertThat(misc).isNull();
is what I expected. Unfortunately both were deleted not Null.
I try to transform the type into HashTable but got:
1 | ERROR: com.google.gson.internal.LinkedTreeMap cannot be cast to java.util.Hashtable |
Solution
Construct an Iterator to get each value in map in sequence (LinkedTreeMap has already did it).
1 | Iterator it = misc.keySet().iterator(); |
不怎么好看不过能用。。
Ref: Gson解析时对于不确定泛型的处理