1

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?

2
  • Post what have you done first. Commented Apr 7, 2016 at 12:42
  • Take a look at spring-data-rest and spring-boot -- it'll do all of this for you with minimal code Commented Apr 7, 2016 at 13:41

2 Answers 2

1

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);
    }
Sign up to request clarification or add additional context in comments.

Comments

0

if you are using Spring then just add produces ={"application/json"} in your REST @RequestMapping and rest thing Spring will do for you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.