java.lang.UnsupportedOperationException: Row map does not support entrySet.
at org.sql2o.data.Row$1.entrySet(Row.java:190)
tasks = con.createQuery(sql).executeAndFetchTable().asList();
Type listOfMaps = new TypeToken<List<Map<String,Object>>>(){}.getType();
Gson gson = new Gson();
resString = gson.toJson(tasks, listOfMaps);
public List<Map<String,Object>> getReportData(){
String complexSql = "...";
try (Connection con = sql2o.open()) {
return con.createQuery(complexSql).executeAndFetchTable().asList();
}
}
I used executeAndFetchTable() and this method as workaround:
private List<Map<String, Object>> tableToList(Table t) {
List<Map<String, Object>> mapList = new ArrayList<>();
for (int i = 0; i < t.rows().size(); i++) {
Map<String,Object> map = new HashMap<>();
for (int j = 0; j < t.columns().size(); j++) {
map.put(t.columns().get(j).getName(), t.rows().get(i).getObject(j));
}
mapList.add(map);
}
return mapList;
}