Issue
I am fetching data from database using Hibernate
, and I am getting the data in the List result_list
I want to send this in the from of JSON to the client.
My Code:
SessionFactory sessionFactory;
Session session = null;
JSONObject jsonObject = new JSONObject();
sessionFactory = HibernateUtility.getSessionFactory();
session = sessionFactory.openSession();
session.beginTransaction();
Criteria criteria = session.createCriteria(UserClass.class);
List<UserClass> result_list = (List<UserClass>) criteria.list();
I want to send result_list in JSON Object with some other info like number rows
and sessionID
Sample Output:
{
"number_of_record":2,
"sesion_id":"sessision343seudur5ivce",
"car": result_list
}
Solution
Create a class namely :
public class JsonSendData {
public int number_of_record;
public string sesion_id;
public List<UserClass> car;
}
Take an instance and set the properties. You can serialize your object as expected.
Answered By - OnurBulbul