private <T> List<T> getRecordList(List<String> events, Class<T> tClass) {
ArrayList<T> list = new ArrayList<>();
if (events != null && events.size() > 0) {
events.forEach(new Consumer<String>() {
@Override
public void accept(String event) {
if (org.springframework.util.StringUtils.isEmpty(event)) return;
T record = null;
try {
record = gson.fromJson(event, tClass);
} catch (Exception e) {
e.printStackTrace();
}
if (record != null) {
list.add(record);
}
}
});
}
return list;
}
https://stackoverflow.com/questions/18397342/deserializing-generic-types-with-gson