List of usage examples for org.springframework.web.servlet.view.json MappingJackson2JsonView MappingJackson2JsonView
public MappingJackson2JsonView()
From source file:com.mmj.app.web.controller.BaseController.java
protected ModelAndView createJsonMav(String code, String msg, Object object) { ModelAndView mav = new ModelAndView(); MappingJackson2JsonView mappingJackson2JsonView = new MappingJackson2JsonView(); mappingJackson2JsonView.getObjectMapper().setSerializationInclusion(Include.NON_NULL); mav.setView(mappingJackson2JsonView); Map<String, Object> map = new HashMap<String, Object>(); map.put("code", code); map.put("message", msg); map.put("data", object); mav.addObject("result", map); return mav;//from w w w. j a v a2 s . c o m }
From source file:com.fengduo.bee.web.controller.product.ItemController.java
private ModelAndView createJsonMav(boolean isSuccess, Long code, String info) { ModelAndView mav = new ModelAndView(); mav.setView(new MappingJackson2JsonView()); mav.addObject("isSuccess", isSuccess); mav.addObject("code", code); mav.addObject("info", info); return mav;// ww w . java2 s.co m }
From source file:com.mmj.app.web.controller.BaseController.java
@Override protected ModelAndView createJsonMav(String msg, ResultCode code, Object object) { ModelAndView mav = new ModelAndView(); mav.setView(new MappingJackson2JsonView()); Map<String, Object> map = new HashMap<String, Object>(); map.put("code", Integer.toString(code.value)); map.put("message", msg); map.put("data", object == null ? StringUtils.EMPTY : object); mav.addObject("result", map); return mav;/* w ww. j a v a2 s . c o m*/ }
From source file:org.encuestame.mvc.page.FileUploadController.java
/** * Upload Profile for User Account./*from www .j a v a 2 s . c o m*/ * @param multipartFile * @return */ @PreAuthorize("hasRole('ENCUESTAME_USER')") @RequestMapping(value = "/file/upload/profile", method = RequestMethod.POST) public ModelAndView handleUserProfileFileUpload(@RequestParam("file") MultipartFile multipartFile) { ModelAndView mav = new ModelAndView(new MappingJackson2JsonView()); if (!multipartFile.isEmpty()) { log.debug(multipartFile.getName()); String orgName = multipartFile.getOriginalFilename(); log.debug("org name " + orgName); //TODO: convert name to numbers, MD5 hash. String filePath = null; try { log.debug("getting file path for this user"); filePath = getPictureService() .getAccountUserPicturePath(getSecurityService().getUserAccount(getUserPrincipalUsername())); InputStream stream = multipartFile.getInputStream(); try { //generate thumbnails thumbnailGeneratorEngine.generateThumbnails(PathUtil.DEFAUL_PICTURE_PREFIX, stream, multipartFile.getContentType(), filePath); } catch (Exception e) { //e.printStackTrace(); log.error(e); } finally { stream.close(); } //TODO: after save image, we need relationship user with profile picture. //I suggest store ID on user account table, to retrieve easily future profile image. //BUG 102 } catch (IllegalStateException e) { //e.printStackTrace(); log.error("File uploaded failed:" + orgName); } catch (IOException e) { //e.printStackTrace(); log.error("File uploaded failed:" + orgName); } catch (EnMeNoResultsFoundException e) { ///e.printStackTrace(); log.error("File uploaded failed:" + orgName); } catch (EnmeFailOperation e) { //e.printStackTrace(); log.error("File uploaded failed:" + orgName); } // Save the file here mav.addObject("status", "saved"); mav.addObject("id", filePath); } else { mav.addObject("status", "failed"); } return mav; }
From source file:org.squashtest.tm.web.internal.exceptionresolver.HandlerGenericValidation.java
@Override protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { if (exceptionIsHandled(ex) && clientAcceptsJson(request)) { response.setStatus(HttpServletResponse.SC_PRECONDITION_FAILED); ConstraintViolationException cve = (ConstraintViolationException) ex; // NOSONAR Type was checked earlier List<FieldValidationErrorModel> errors = buildFieldValidationErrors(cve); return new ModelAndView(new MappingJackson2JsonView(), "fieldValidationErrors", errors); }//from w w w.j av a 2 s. c om return null; }