springmvccontroller返回json出错解决
1、出错的地方:
@RequestMapping(value = "/query")
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
public @ResponseBody
JSONObject query(@RequestParam("startTime") String startTime,
@RequestParam("endTime") String endTime,
@RequestParam("oid") String oid, @RequestParam("cid") Integer cid,
@RequestParam("pay_channel") String payChannel,
@RequestParam("device_type") String deviceType,
@RequestParam("phone") Integer phone,
@RequestParam("perPage") Integer pageSize,
@RequestParam("skipIndex") Integer startIndex) throws Exception {
 
LogInfo info = populateQueryParam(startTime, endTime, oid, cid,
payChannel, deviceType, phone, pageSize, startIndex);
 
// 总记录数
Long totalCount = logMoniterService.queryLogInfoCount(info);
springmvc选择题 
if (totalCount == null) {
totalCount = 0L;
}
 
List<LogInfo> list = logMoniterService.queryLogInfo(info);
 
JSONObject retData = new JSONObject();
retData.put("success", true);
retData.put("data", list);
retData.put("error", "");
retData.put("totalRecords", totalCount);
return retData;
}
 
2、结果报错:
<html><head><title>Apache Tomcat/7.0.42 - Error report</title><style></style> </head><body><h1>HTTP Status 500 - Could not write JSON: Object is null (through reference chain: net.sf.json.JSONObject["data"]->net.sf.json.JSONArray[0]->net.sf.json.JSONObject["createTime"]->net.sf.json.JSONNull["empty"]); nested exception dehaus.jackson.map.JsonMappingException: Object is null (through reference chain: net.sf.json.JSONObject["data"]->net.sf.json.JSONArray[0]->net.sf.json.JSONObject["createTime"]->net.sf.json.JSONNull["empty"])</h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u>Could not write JSON: Object is null (through reference chain: net.sf.json.JSONObject["data"]->net.sf.json.JSONArray[0]->net.sf.json.JSONObject["createTime"]->net.sf.json.JSONNull["empty"]); nested exception dehaus.jackson.map.JsonMappingException: Object is null (through reference cha
in: net.sf.json.JSONObject["data"]->net.sf.json.JSONArray[0]->net.sf.json.JSONObject["createTime"]->net.sf.json.JSONNull["empty"])</u></p><p><b>description</b> <u>The server encountered an internal error that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>org.verter.HttpMessageNotWritableException: Could not write JSON: Object is null (through reference chain: net.sf.json.JSONObject["data"]->net.sf.json.JSONArray[0]->net.sf.json.JSONObject["createTime"]->net.sf.json.JSONNull["empty"]); nested exception dehaus.jackson.map.JsonMappingException: Object is null (through reference chain: net.sf.json.JSONObject["data"]->net.sf.json.JSONArray[0]->net.sf.json.JSONObject["createTime"]->net.sf.json.JSONNull["empty"])
org.verter.json.MappingJacksonHttpMessageConverter.writeInternal(MappingJacksonHttpMessageConverter.java:203)
org.verter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:179)
org.springframework.web.hod.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:148)
org.springframework.web.hod.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:90)
org.springframework.web.hod.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:189)
org.hod.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:69)
org.springframework.web.hod.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:122)
org.springframework.web.hod.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
org.springframework.web.hod.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
org.springframework.web.hod.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
org.apache.shiro.web.uteChain(AdviceFilter.java:108)
org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
org.apache.shiro.web.uteChain(AbstractShiroFilter.java:449)
org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。