How to Return JSON after successful POST of a record
I have enabled json for my project with:
web mvc json setup
web mvc json all --package ~.web
I am able to create record with curl such as
curl -i -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '[{name: "Cheesy Crust"},{name: "Thick Crust"}]' http://localhost:8080/pizzashop/bases/jsonArray
However, upon successful creation of a record, there seems to be no json in the response. I just see something like:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json;charset=utf-8
Content-Length: 831
Date: Sun, 24 Feb 2013 16:44:44 GMT
I want to see at least the id of the row I had just created. What's the recommended approach in roo? Modify the controller_Json.aj file? Or is there a better method?
I've noticed that in the getters that roo created, it's throwing back <object>.toJsonArray(result). Do I need to do this for the create as well?
@RequestMapping(headers = "Accept=application/json")
@ResponseBody
public ResponseEntity<String> AgendaItemController.listJson() {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
List<AgendaItem> result = agendaItemService.findAllAgendaItems();
return new ResponseEntity<String>(AgendaItem.toJsonArray(result), headers, HttpStatus.OK);