Look into the collection examples.
Modify your code to use collections of hash maps to serialize and deserialize.
Serialization:
Collection<HashMap<String, String>> details = new List<HashMap<String, String>>();
// add contents
String json = gson.toJson(details);
Deserialization:
String json = // read in file content
Type collectionType = new TypeToken<Collection<HashMap<String, String>>>(){}.getType();
Collection<HashMap<String, String>> details2 = gson.fromJson(json, collectionType);
In the "Collections limitations" part is written the following:
While deserializing, Collection must be of a specific generic type
I'm not sure, but that could mean, that you have to to set collectionType
to use List
and not Collection
as specific type.