If I have 'n' number of methods like this, is there a way out by which I can optimize this and make it a single function?
Or are there other better options by which I can make this more generic?
public List<Address> getAddressList(String response) {
List<Address> AddressList = new ArrayList<Address>();
if (response != null && response.length() > 0) {
try {
Gson gson = new Gson();
Type collectionType = new TypeToken<List<Address>>(){}.getType();
AddressList = gson.fromJson(response, collectionType);
} catch (IllegalStateException ex) {
} catch (Exception ex) {
}
}
return AddressList;
}
public List<Tweet> getTweetList(String response) {
List<Tweet> tweetList = new ArrayList<Tweet>();
if (response != null && response.length() > 0) {
try {
Gson gson = new Gson();
Type collectionType = new TypeToken<List<Tweet>>(){}.getType();
tweetList = gson.fromJson(response, collectionType);
} catch (IllegalStateException ex) {
} catch (Exception ex) {
}
}
return tweetList;
}