1

Spring 3 has native json support for returning json response using @ResponseBody spring 3 annotation.

My app is based on spring 2 and need to create jackson based rest service which will return json when client make http rest request using browser.

I am exploring how to achieve this. Any body suggestions on this is appreciated.

Thanks

S Singh
  • 1,403
  • 9
  • 31
  • 47

1 Answers1

2

In Spring 3 we have default converter which converts any object (using Jackson) to JSON. We can override this default converter to define some specials settings. In Spring 2 we can implement View. You can implement this view using Jackson library to convert any object to JSON.

Your controller could look like that:

public ModelAndView generateJson(.....) {
     //business logic

     return new ModelAndView(new JsonView(objectToConvert);
}
Michał Ziober
  • 37,175
  • 18
  • 99
  • 146