springmvccontroller返回json出错解决 下载本文

内容发布更新时间 : 2024/6/16 18:46:57星期一 下面是文章的全部内容请认真阅读。

springmvccontroller返回json出错解决

1、出错的地方:

@RequestMapping(value = \

@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) public @ResponseBody

JSONObject query(@RequestParam(\@RequestParam(\

@RequestParam(\@RequestParam(\@RequestParam(\@RequestParam(\@RequestParam(\

@RequestParam(\

LogInfo info = populateQueryParam(startTime, endTime, oid, cid, payChannel, deviceType, phone, pageSize, startIndex);

// 总记录数

Long totalCount = logMoniterService.queryLogInfoCount(info);

if (totalCount == null) { totalCount = 0L; }

List list = logMoniterService.queryLogInfo(info);

JSONObject retData = new JSONObject(); retData.put(\ retData.put(\ retData.put(\

retData.put(\ return retData; }

2、结果报错:

Apache Tomcat/7.0.42 - Error report

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 is

org.codehaus.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"])


message 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 is

org.codehaus.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"])

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.http.converter.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 is 

org.codehaus.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.springframework.http.converter.json.MappingJacksonHttpMessageConverter.writeInternal(MappingJacksonHttpMessageConverter.java:203) org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:179)

org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:148)

org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:90)

org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:189)

org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:69)

org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:122)

org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)

org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686) org.springframework.web.servlet.mvc.method.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.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)

org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)