Smile is compact representation of JSON in binary format that represents JSON data in a more efficient manner than regular text-based JSON. The idea is leverage the use of binary JSON to cut down on the amount of data communicated between client and server.
On the server side, FasterXML/jackson Java lib is used to return JSON data in Smile format (binary JSON as follows:
OutputStream os = response.getOutputStream();
SmileFactory factory = new SmileFactory();
SmileGenerator generator = (SmileGenerator)
factory.createGenerator(os);
generator.writeStartObject();
generator.writeFieldName("sEcho");
generator.writeString(sEcho);
...
generator.writeEndObject();
generator.close();
When attempting to switch Datatables to use binary JSON as per recommendation, the ajax option to Datatables construction was added as per below, but error message "Invalid JSON response" is outputted on load of data-tables. Any ideas how to resolve?
"ajax": {
"url": "fetchtabledata.do?" + "instance=<c:out value="${resultsBean.instance}"/>",
"dataType": "binary",
"dataSrc": function ( json ) {
return Smile.Parser.parse(json);
}
},