How do I concatenate two arrays and then return the result as JSON to DataTables?
I am converting a working DataTables to include server-side processing and am stuck on returning the correct array from the java server-side. Currently the array returned is:
List<YthMmbrSectDtls> ymList;
Example data is:
[{"youthMemberID":"MTQ5","surname":"Tendon","firstName":"Achilles"}]
With the DataTables server-side I need to include extra information at the start of the returned JSON such as:
{"draw":9, "recordsTotal:57", "recordsFiltered:57"[...]}
So that I return:
{"draw":9, "recordsTotal:57", "recordsFiltered:57","data":[{"youthMemberID":"MTQ5","surname":"Tendon","firstName":"Achilles"}]}
At least that is my understanding from reading the manuals and watching the videos.
My current code is:
List<YthMmbrSectDtls> ymList;
String[] dtInfo = {"draw", "recordsTotal", "recordsFiltered"};
ymList = MySQLConnection.getYouthMmbrAllDtls(archived);
//Test to be replaced by database call, as per above
dtInfo[0] = "9";
dtInfo[1] = "57";
dtInfo[2] = "57";
if (ymList == null || ymList.isEmpty()) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No members.");
} else {
System.out.println("ymList: " + ymList);
String json = new Gson().toJson(ymList);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json);
}