Just enter the data in the collection or map of full Javabeans and use Google Gson to easily convert it to JSON. JSON is more compact than XML, and it is much easier to process it in JavaScript (this is also the designation of JavaScript objects ).
All you basically need to do with Gson is the following:
List<Data> list = dataDAO.list();
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(new Gson().toJson(list));
It's all. I have already answered this several times with examples: here , here , here and here .
source
share