I have a Spring MVC backend that needs to start handling new URLs that will be hit by client-side jQuery/AJAX calls. These calls are expecting JSON objects to be returned by the server.
I am trying to follow a few examples I was able to find and here’s what I have so far:
// AjaxResult.java
public class AjaxResult {
private int answer;
private String errMsg;
// Getters/setters for both properties.
}
// Inside MyController.java (a Spring @Controller):
public @ResponseBody AjaxResult handleJQueryCall(@RequestParam("x") String whatever) {
int ans = calculateSomething(whatever);
AjaxResult result = new AjaxResult(ans);
return result;
}
I’m not in a position where I can compile/deploy this, but there’s clearly something missing here…the use of Jackson! So I ask: how do I specify that the AjaxResult result gets returned by Spring, to the client-side, as JSON? Thanks in advance!
I think You are missing the mapping :