I have a method in the controller that will return HTML or JSON depending on what was requested. Here's a stripped down example of such a method, modeled after the information on how to do this, which I found in this question :
@RequestMapping(value="callback")
public ModelAndView callback(@RequestParam("c") String c) {
Map response = new HashMap<String, String>();
response.put("foo", "bar");
return new ModelAndView("fake", "data", new JSONPObject(c, response));
}
I put a JSONPObject in the model because I need to be able to get it from a view that displays if HTML was requested. But this poses a problem when I handle JSON with a callback:
curl 'http://localhost:8080/notes/callback.json?c=call'
{"data"call(:{"foo":"bar"})}
As you can see, since I put my data in the βdataβ slot in the model, when the model is displayed as JSON, there is additional packaging. What I'm looking for is a JSON rendering (technically JSONP), which looks like this:
call({"data":{"foo":"bar"}})
- , , , JSONPObject ?