Hi all,
I am playing with "json add" to my entity managing controllers (roo 1.1.5, hibernate 3.6.4, spring 3.0.5, sts 2.8.1) . The *_ROO_Controller_Json ITD contains a method createFromJson:
when doing aCode:@RequestMapping(method = RequestMethod.POST, headers = "Accept=application/json") public ResponseEntity<String> DataController.createFromJson(@RequestBody String json) { ...
the json string will be empty because the Content-Type of the request is application/x-www-form-urlencoded. It is not picked up by the @RequestBody. You will see a FlexJson error: "Stepping back two steps is not supported" accompanied by a nice stack trace.Code:> curl -i -X POST -H 'Accept: application/json' -d @document.json http://localhost:8080/application/datas
The request with the Content-Type:
works fine.Code:> curl -i -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d @document.json http://localhost:8080/application/datas
Should the @RequestMapping of the Controller ITD refuse Content-Types which are not application/json with a nice 404 or similar?
I have tried this
but it did not work. Are multiple headers allowed?Code:@RequestMapping(method = RequestMethod.POST, headers = {"accept=application/json","content-type=application/json"})
Or should the ITD template check if the json string is empty or null before calling the fromJsonToData method on the corresponding entity?
Cheers
Carsten


Reply With Quote
