Render ModelAndView manually?
I need to render ModelAndView in my controller manually in order to put it inside JSON object. If I pass the whole ModelAndView object into to JSON I开发者_StackOverflow get " no serializer found for class javassistlazyinitializer" exception because jackson can't work properly with LAZY-objects. Thank you
public class JSONView implements View {
/**
* Logger for this class
*/
private static final Logger logger = Logger.getLogger(JSONView.class);
private String contentType = "application/json";
public void render(Map map, HttpServletRequest request, HttpServletResponse response)
throws Exception {
if(logger.isDebugEnabled()) {
logger.debug("render(Map, HttpServletRequest, HttpServletResponse) - start");
}
JSONObject jsonObject = new JSONObject(map);
PrintWriter writer = response.getWriter();
writer.write(jsonObject.toString());
if(logger.isDebugEnabled()) {
logger.debug("render(Map, HttpServletRequest, HttpServletResponse) - end");
}
}
public String getContentType() {
return contentType;
}
}
ModelAndView returnModelAndView = new ModelAndView(new JSONView(), model);
精彩评论