I am trying to make a generic method for data deserialization.
My code:
public <T> ExportedData<T> getExportData(T classType, String exportUri) {
Response response = _client.get(exportUri);
// System.out.println(response.body.toString());
ExportedData<T> exportedData = GsonSingleton.getGson().fromJson(response.body.toString(), new TypeToken<ExportedData<T>>() {
}.getType());
return exportedData;
}
The response.body
:
{"totalResults":2,"limit":50000,"offset":0,"count":2,"hasMore":false,"items":[{"DevicesIDs":"","EmailAddress":"zatokar@gmail.com"},{"DevicesIDs":"","EmailAddress":"oto@increase.dk"}]}
The way I call the generic method:
ExportedData<AccengageOutboundContact> exportedData = generalBulkHelper.getExportData(new AccengageOutboundContact(), uriLimitAndOffset);
The AccengageOutboundContact
:
public class AccengageOutboundContact {
public String EmailAddress;
public String DevicesIDs;
}
And the ExportedData
:
public class ExportedData<T> {
public int totalResults;
public int limit;
public int offset;
public int count;
public boolean hasMore;
public List<T> items;
}
I would expect to get an ArrayList of AccengageOutboundContact
objects. What I am getting is ArrayList of StringMap
.
Any idea what am I doing wrong?