alibaba / fastjson2

🚄 FASTJSON2 is a Java JSON library with excellent performance.
Apache License 2.0
3.69k stars 478 forks source link

[BUG] fastjson2 2.0.16版本及以上报Cannot read field "child0" because "this.path" is null错误 #1085

Closed creky closed 1 year ago

creky commented 1 year ago

问题描述

2.0.16版本及以上报Cannot read field "child0" because "this.path" is null错误

环境信息

重现步骤

调用 jfinal.json.FastJson.toJson 方法

期待的正确结果

不要报错

相关日志输出

java.lang.NullPointerException: Cannot read field "child0" because "this.path" is null at com.alibaba.fastjson2.JSONWriter.setPath(JSONWriter.java:194) at com.alibaba.fastjson2.writer.ObjectWriterImplList.write(ObjectWriterImplList.java:365) at com.alibaba.fastjson.JSON.toJSONStringWithDateFormat(JSON.java:1760) at com.jfinal.json.FastJson.toJson(FastJson.java:55)

附加信息

经查原因是com.alibaba.fastjson2.JSONWriter#JSONWriter构造函数没有设置默认的path值。在里面设置个: path = JSONWriter.Path.ROOT; 就可以了?

wenshao commented 1 year ago

这个问题修复过,可以帮忙用2.0.23版本做下验证么?

creky commented 1 year ago

这个问题修复过,可以帮忙用2.0.23版本做下验证么?

经验证,2.0.23版本仍然 没有被修复。仍然报同样的错误。 调用的语句为:JSON.toJSONStringWithDateFormat(object, “yyyy-MM-dd HH:mm:ss”, SerializerFeature.WriteDateUseDateFormat);

wenshao commented 1 year ago

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.24-SNAPSHOT/ 问题已修复,请用2.0.24-SNAPSHOT版本帮忙验证,2.0.24-SNAPSHOT预计在2月中旬发布。

creky commented 1 year ago

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.24-SNAPSHOT/ 问题已修复,请用2.0.24-SNAPSHOT版本帮忙验证,2.0.24-SNAPSHOT预计在2月中旬发布。

经确认,已经修复~~~~