admin 管理员组文章数量: 1086019
2024年3月8日发(作者:press怎么记忆)
springmvccontroller返回json出错解决
1、出错的地方:
@RequestMapping(value = "/query")
@JsonSerialize(include=_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 = ogInfoCount(info);
if (totalCount == null) {
totalCount = 0L;
}
List
JSONObject retData = new JSONObject();
("success", true);
("data", list);
("error", "");
("totalRecords", totalCount);
return retData;
}
2、结果报错:
report
HTTP Status 500 - Could not write
JSON: Object is null (through reference chain:
ject["data"]->ray[0]->ject["createTime"]->ll["empty"]); nested exception is
ppingException: Object is null (through
reference chain:
ject["data"]->ray[0]->ject["createTime"]->ll["empty"])
noshade="noshade">
type Exception report
message
Could not write JSON: Object is null (through reference chain:
ject["data"]->ray[0]->ject["createTime"]->ll["empty"]); nested exception is
ppingException: Object is null (through
reference chain:
ject["data"]->ray[0]->ject["createTime"]->ll["empty"])
description The server
encountered an internal error that prevented it from fulfilling this
request.
exception
ssageNotWritableException: Could not write JSON: Object is null (through reference chain:ject["data"]->ray[0]->ject["createTime"]->ll["empty"]); nested exception is
ppingException: Object is null (through
reference chain:
ject["data"]->ray[0]->ject["createTime"]->ll["empty"])
nternal(:203)
(:179)
ithMessageConverters(:148)
ithMessageConverters(:90)
ReturnValue(:189)
ReturnValue(:69)
AndHandle(:122)
HandleMethod(:745)
Internal(:686)
(:80)
atch(:925)
ice(:856)
sRequest(:936)
(:838)
e(:647)
e(:812)
e(:728)
er(:61)
eChain(:108)
erInternal(:137)
er(:125)
er(:66)
eChain(:449)
ctShiroFilter$(:365)
(:90)
(:83)
e(:383)
erInternal(:362)
er(:125)
Delegate(:343)
er(:260)
erInternal(:88)
er(:107)
root cause
ppingException: Object is null(through reference chain:
ject["data"]->ray[0]->ject["createTime"]->ll["empty"])
thPath(:218)
thPath(:183)
dThrow(:140)
3原因分析:
可能是json序列化的问题
代码修改为
@RequestMapping(value = "/query")
public @ResponseBody
Map
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 = ogInfoCount(info);
if (totalCount == null) {
totalCount = 0L;
}
List
list = ogInfo(info);
Map
result = new HashMap ();
("success", true);
("data", list);
("error", "");
("totalRecords", totalCount);
return result;
}
4、问题解决
版权声明:本文标题:springmvccontroller返回json出错解决 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/b/1709853041a548232.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论