@RequestMapping @ResponseBody @JsonView(MyJacksonView2.class) public JacksonViewBean handleResponseBody() { JacksonViewBean bean = new JacksonViewBean(); bean.setWithView1("with"); bean.setWithView2("with"); bean.setWithoutView("without"); return bean; }
@RequestMapping @JsonView(MyJacksonView2.class) public ResponseEntity<JacksonViewBean> handleResponseEntity() { JacksonViewBean bean = new JacksonViewBean(); bean.setWithView1("with"); bean.setWithView2("with"); bean.setWithoutView("without"); ModelAndView mav = new ModelAndView(new MappingJackson2JsonView()); mav.addObject("bean", bean); return new ResponseEntity<JacksonViewBean>(bean, HttpStatus.OK); }