Mapping Complex data to customized gson Handlers

Its for exporting and importing Patient data. So I had planned to store the data in a Map<String, Resource> . Is there a better implementation?

So I’m planning to serialize the Map with data. The challenge is with deserialization. Actually casting a Resource to its type to be more specific.

Around. I tried to implement a deserialization handler but I need guidance here.

Btw, I made a mistake up there which am gonna edit. The Map looks like

Map<String, ArrayList<Resource>> store;

where we could add data like

List<Patient>  patients = new ArrayList<Patient>();
List<Location> locations = new ArrayList<Location>();

// TODO :- Add some data to the lists.

HashMap<String, Resource> store = getStore();

//Add patient data to be serialized.
store.add("Patient", patients);
store.add("Location", locations);

//Serialize
String json = gson.toJson(store);

//Deserialize
HashMap<String,  ArrayList<Resource>> deserializedData = gson.fromJson(json, HashMap<String, ArrayList<Resource>>);

//Try to retrieve Patient data.
List<Resource> patients = deserializedData.get("Patient");
for(Resource pat : patients) {
     Patient patient = (Patient)pat;//Ooooppsss, throws ClassCastException : gson.internal.LinkedTreeMap cannot be cast to Patient.class

}

Now I realised I had to implement a deserialization Handler. Thats were I need yr help.

The above code my have typos. I have been just typing it from here just quickly