I created a controller with method handler as
@RequestMapping( value = {"/membersjson"},method = RequestMethod.GET)
public @ResponseBody String getMembers(Model model) {
List<Member> members = memberService.getMembers();
model.addAttribute("members",members);
return "jsontemplate";
}
<bean id="jsontemplate"
class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
I expect the out put to be in json but instead the output is “jsontemplate” instead. Can some one please explain the reason. thanks in advance.
MappingJacksonJsonView, or any other view or view resolver bean, is irrelevant when you’re using@ResponseBody. Instead, Spring will try to convert the return value of your method directly into a response. In this case, it’s decided to turn it into a String response.First make, sure you’ve declared
<mvc:annotation-driven/>in your context, and that Jackson is available on the classpath. Also ensure that the browser is sendingapplication/jsonin itsAcceptheader.