當前位置: 首頁>>代碼示例>>Java>>正文


Java MappingJackson2JsonView.setObjectMapper方法代碼示例

本文整理匯總了Java中org.springframework.web.servlet.view.json.MappingJackson2JsonView.setObjectMapper方法的典型用法代碼示例。如果您正苦於以下問題:Java MappingJackson2JsonView.setObjectMapper方法的具體用法?Java MappingJackson2JsonView.setObjectMapper怎麽用?Java MappingJackson2JsonView.setObjectMapper使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.web.servlet.view.json.MappingJackson2JsonView的用法示例。


在下文中一共展示了MappingJackson2JsonView.setObjectMapper方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: resolveException

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入方法依賴的package包/類
@Override
	public ModelAndView resolveException(HttpServletRequest request,
		 HttpServletResponse response, Object handler, Exception e) {
		// log記錄異常
		LOGGER.error(e.getMessage(), e);
		// 非控製器請求照成的異常
		if (!(handler instanceof HandlerMethod)) {
			return new ModelAndView("error/500");
		}
		HandlerMethod handlerMethod = (HandlerMethod) handler;

		if (WebUtils.isAjax(handlerMethod)) {
			Result result = new Result();
			result.setMsg(e.getMessage());
			MappingJackson2JsonView view = new MappingJackson2JsonView();
			view.setObjectMapper(jacksonObjectMapper);
			view.setContentType("text/html;charset=UTF-8");
			return new ModelAndView(view, BeanUtils.toMap(result));
		}

		// 頁麵指定狀態為500,便於上層的resion或者nginx的500頁麵跳轉,由於error/500不適合對用戶展示
//		response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		return new ModelAndView("error/500").addObject("error", e.getMessage());
	}
 
開發者ID:TomChen001,項目名稱:xmanager,代碼行數:25,代碼來源:ExceptionResolver.java

示例2: generateModelAndViewForErrorResponse

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入方法依賴的package包/類
/**
 * Reusable static method for generating a ModelAndView that will be serialized to a JSON representation of the
 * DefaultErrorContractDTO.
 *
 * @return A ModelAndView that will be serialized to a JSON representation of the DefaultErrorContractDTO. (NOTE:
 * make sure the DefaultErrorContractDTO is FULLY populated before calling this method! Changes to the
 * DefaultErrorContractDTO after calling this method may not be reflected in the returned ModelAndView).
 */
public ModelAndView generateModelAndViewForErrorResponse(
    DefaultErrorContractDTO errorContractDTO, int httpStatusCode, Collection<ApiError> rawFilteredApiErrors,
    Throwable originalException, RequestInfoForLogging request
) {
    MappingJackson2JsonView view = new MappingJackson2JsonView();
    view.setExtractValueFromSingleKeyModel(true);
    view.setObjectMapper(getObjectMapperForJsonErrorResponseSerialization(
        errorContractDTO, httpStatusCode, rawFilteredApiErrors, originalException, request
    ));
    ModelAndView mv = new ModelAndView(view);
    mv.addObject(errorContractDTO);
    return mv;
}
 
開發者ID:Nike-Inc,項目名稱:backstopper,代碼行數:22,代碼來源:SpringApiExceptionHandlerUtils.java

示例3: configureViewResolvers

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入方法依賴的package包/類
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
	MappingJackson2JsonView mappingJackson2JsonView = new MappingJackson2JsonView();
	mappingJackson2JsonView.setObjectMapper(objectMapper);
	registry.enableContentNegotiation(true, mappingJackson2JsonView);
	registry.viewResolver(viewResolver);
}
 
開發者ID:candrews,項目名稱:availability,代碼行數:8,代碼來源:WebMvcConfig.java

示例4: defaultView

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入方法依賴的package包/類
@Bean
public View defaultView() {
  MappingJackson2JsonView bean = new MappingJackson2JsonView();
  bean.setObjectMapper(jsonObjectMapper());
  return bean;
}
 
開發者ID:smah3sh,項目名稱:mcs,代碼行數:7,代碼來源:MatchmakerCloudSearchConfiguration.java


注:本文中的org.springframework.web.servlet.view.json.MappingJackson2JsonView.setObjectMapper方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。