trouble serialize results - executeAndFetchTable().asList()

300 views
Skip to first unread message

ro...@uwf.edu

unread,
Jul 8, 2015, 12:48:25 AM7/8/15
to sq...@googlegroups.com

Trying to serialize the result of a simple select query.
I am getting 

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);


martina...@gmail.com

unread,
Apr 20, 2016, 9:06:35 AM4/20/16
to sql2o, ro...@uwf.edu
I am getting the same problem.

I tried the example from the web site which didn't work:

public List<Map<String,Object>> getReportData(){
    String complexSql = "...";

    try (Connection con = sql2o.open()) {
        return con.createQuery(complexSql).executeAndFetchTable().asList();
    }
}


It simply returns : 

System.out.println(getReportData);

[org.sql2o.data.Row$1@134886f7, org.sql2o.data.Row$1@1d213cfa, org.sql2o.data.Row$1@7e68e907, org.sql2o.data.Row$1@2c1bc3d2, org.sql2o.data.Row$1@7b338798]

martina...@gmail.com

unread,
Apr 21, 2016, 5:14:07 AM4/21/16
to sql2o, ro...@uwf.edu
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;
   
}

costa...@gmail.com

unread,
Nov 20, 2017, 4:47:41 AM11/20/17
to sql2o
I had a similar issue in scala but I solved it by casting row.asMap() to HashMap.
Message has been deleted

costa...@gmail.com

unread,
Nov 20, 2017, 5:23:40 AM11/20/17
to sql2o
Sorry, I thought that the cast would fix the issue and I posted the message before trying it. It seems that the latest version of the source code creates the Row.asMap as a HashMap and I thought that that change was made a long time ago, but it turns out it is only in version 1.6.0-RC3. So, upgrading to this version got rid of the error.
Reply all
Reply to author
Forward
0 new messages