How can I return JSON from spring controller as a view or ModelAndView? I am not interested in using @ResponseBody annotation. Is there any other way of doing this?
ModelAndView
@ResponseBody
Yes, you can return a MappingJacksonJsonView or assign it to a ModelAndView object using mav.setView(new MappingJacksonJsonView()).
MappingJacksonJsonView
mav.setView(new MappingJacksonJsonView())
Update: In Spring 4 MappingJacksonJsonView is deprecated. You might want to upgrade to MappingJackson2JsonView
2.1m questions
2.1m answers
60 comments
57.0k users