Reputation: 97
I have table employee
which has the columns EMPID
, EMPNAME
, EMPAGE
, SALARY
, ADDRESS
, department_id
(foreign key to department_id in department) and another table department
which has department_id
, name
. So I made a query
List<Department> deps = sessionFactory.getCurrentSession().createCriteria(Department.class).list();
The return vlaue is a List of Lists
I want to put the result in in JSON Object. How can I achieve this?
Upvotes: 1
Views: 2600
Reputation: 1
if you are using Spring then just add produces ={"application/json"}
in your REST @RequestMapping
and rest thing Spring will do for you
Upvotes: 0
Reputation: 5387
Do something like this
List<List<Object>> listOfLists = new ArrayList<>();
JSONArray jsonArray = new JSONArray();
for (List<Object> list : listOfLists) {
JSONArray newArray = new JSONArray(list);
jsonArray.put(newArray);
}
Upvotes: 1