I have a Spring controller method that is correctly returning a collection of objects in the JSON to the client:
@RequestMapping(value="/admin/rawreads/unknowntags", method=RequestMethod.GET)
public @ResponseBody Collection<RawRead> getRawReadsWithUnknownTag() {
....
}
I’m trying to integrate a jQuery addon/plugin called DataTables. DataTables can handle the asynchronous request to fetch data and populate a table in the page for me, however it requires the data to be return in an array with a specific name “aaData” rather than the current format of :
[{"oid":149452,"date":1233076733000,"readerId":"811210008","recordNo":226,"tagCode":"0103A003C0","reader":null,"guard":null,"checkpoint":null},{"oid":149453,"date":1233076734000,"readerId":"8112100 .... etc]
Suggested return format for DataTables from the DataTable docs:
{
"sEcho": 1,
"iTotalRecords": "n",
"iTotalDisplayRecords": "n",
"aaData": [
[object1][object2].... etc
]
}
How can I change my Java method to return data in the format DataTables needs – a named array?
EDIT:
Tried putting vars into a HashMap serverside, gets a bit closer to what I need:
{"iTotalDisplayRecords":3050,"iTotalRecords":3050,"aaData":
[{"oid":149452,"date":1233076733000, ...<snip>},{...}]
}
Make a separate class in the correct format for data tables, having fields for sEcho, itotalrecords, ittotaldisplayrecords and then an array called aaData.
Then return this class via jason and that is then in your suggested format.
Obviously assign data to these fields and proper accessors etc!