Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring: return JSON from controller as ModelAndVIew

Tags:

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?

like image 281
Arjun Avatar asked May 30 '11 06:05

Arjun


1 Answers

Yes, you can return a MappingJacksonJsonView or assign it to a ModelAndView object using mav.setView(new MappingJacksonJsonView()).

Update: In Spring 4 MappingJacksonJsonView is deprecated. You might want to upgrade to MappingJackson2JsonView

like image 128
Sean Patrick Floyd Avatar answered Oct 25 '22 10:10

Sean Patrick Floyd