NutzCN Logo
问答 执行toJson()方法报异常
发布于 3203天前 作者 qq_561f5fd6 2277 次浏览 复制 上一个帖子 下一个帖子
标签: json

执行这个方法报异常,排查了下原因,是因为方法的名称是 toJson() 造成的,改成其他名称就好了,这应该是个bug。
```js\n
public String toJson() {
return String.format("/*%s*/%s", super.toString(),
Json.toJson(this, JsonFormat.compact()));

}
\n```

at com.young.seagull.base.BaseBean.toJson(BaseBean.java:44)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.nutz.json.impl.JsonRenderImpl.pojo2Json(JsonRenderImpl.java:236)
at org.nutz.json.impl.JsonRenderImpl.render(JsonRenderImpl.java:125)
at org.nutz.json.Json.toJson(Json.java:225)
at org.nutz.json.Json.toJson(Json.java:187)
at com.young.seagull.base.BaseBean.toJson(BaseBean.java:44)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.nutz.json.impl.JsonRenderImpl.pojo2Json(JsonRenderImpl.java:236)
at org.nutz.json.impl.JsonRenderImpl.render(JsonRenderImpl.java:125)
at org.nutz.json.Json.toJson(Json.java:225)
at org.nutz.json.Json.toJson(Json.java:187)
at com.young.seagull.base.BaseBean.toJson(BaseBean.java:44)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.nutz.json.impl.JsonRenderImpl.pojo2Json(JsonRenderImpl.java:236)
at org.nutz.json.impl.JsonRenderImpl.render(JsonRenderImpl.java:125)
at org.nutz.json.Json.toJson(Json.java:225)
at org.nutz.json.Json.toJson(Json.java:187)
at com.young.seagull.base.BaseBean.toJson(BaseBean.java:44)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.nutz.json.impl.JsonRenderImpl.pojo2Json(JsonRenderImpl.java:236)
at org.nutz.json.impl.JsonRenderImpl.render(JsonRenderImpl.java:125)
at org.nutz.json.Json.toJson(Json.java:225)
at org.nutz.json.Json.toJson(Json.java:187)
at com.young.seagull.base.BaseBean.toJson(BaseBean.java:44)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.nutz.json.impl.JsonRenderImpl.pojo2Json(JsonRenderImpl.java:236)
at org.nutz.json.impl.JsonRenderImpl.render(JsonRenderImpl.java:125)
at org.nutz.json.Json.toJson(Json.java:225)
at org.nutz.json.Json.toJson(Json.java:187)
at com.young.seagull.base.BaseBean.toJson(BaseBean.java:44)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.nutz.json.impl.JsonRenderImpl.pojo2Json(JsonRenderImpl.java:236)
at org.nutz.json.impl.JsonRenderImpl.render(JsonRenderImpl.java:125)
at org.nutz.json.Json.toJson(Json.java:225)
at org.nutz.json.Json.toJson(Json.java:187)
at com.young.seagull.base.BaseBean.toJson(BaseBean.java:44)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.nutz.json.impl.JsonRenderImpl.pojo2Json(JsonRenderImpl.java:236)
at org.nutz.json.impl.JsonRenderImpl.render(JsonRenderImpl.java:125)
at org.nutz.json.Json.toJson(Json.java:225)
at org.nutz.json.Json.toJson(Json.java:187)
at com.young.seagull.base.BaseBean.toJson(BaseBean.java:44)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.nutz.json.impl.JsonRenderImpl.pojo2Json(JsonRenderImpl.java:236)
at org.nutz.json.impl.JsonRenderImpl.render(JsonRenderImpl.java:125)
at org.nutz.json.Json.toJson(Json.java:225)
at org.nutz.json.Json.toJson(Json.java:187)

2 回复

会无限递归的,你要是自己声明了 toJson,就不要再调用 Json.toJson 了
这个设计是考虑到有些人想输出
{
a: function(){xxxx}
}
这样的字符串,所以就干脆给个函数,自己随便怎么输出去

因为规则就是这样,哈哈,不是bug

添加回复
请先登陆
回到顶部