Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]序列化对象中含有 File 对象就会抛 StackOverflowError 异常 #312

Closed
lyhu opened this issue May 22, 2022 · 2 comments
Closed
Labels
bug Something isn't working
Milestone

Comments

@lyhu
Copy link

lyhu commented May 22, 2022

问题描述

序列化对象中含有 File 对象就会抛 StackOverflowError 异常

环境信息

请填写以下信息:

  • OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]
  • JDK信息: [e.g.:Openjdk 1.8.0_312]
  • 版本信息:[e.g.:Fastjson2 2.0.3]

重现步骤

如何操作可以重现该问题:

  1. 使用 SON.toJSONString 方法
  2. 序列化对象中含有 File 对象就会抛 StackOverflowError 异常,
    public static void main(String[] args) {

        File file = new File("/User/xxx/JsonTest.java");
        Map<String, Object> map = new HashMap<>();
        map.put("file", file);
        System.out.println(JSON.toJSONString(map));
}

期待的正确结果

fastjson1 可以序列化

相关日志输出

Exception in thread "main" java.lang.StackOverflowError
at com.alibaba.fastjson2.writer.ObjectWriterProvider.getObjectWriter(ObjectWriterProvider.java:100)
at com.alibaba.fastjson2.JSONWriter.getObjectWriter(JSONWriter.java:379)
at com.alibaba.fastjson2.writer.FieldWriterObject.getObjectWriter(FieldWriterObject.java:49)
at com.alibaba.fastjson2.writer.ObjectWriter_1.write(Unknown Source)
at com.alibaba.fastjson2.writer.ObjectWriter_1.write(Unknown Source)
at com.alibaba.fastjson2.writer.ObjectWriter_1.write(Unknown Source)
at com.alibaba.fastjson2.writer.ObjectWriter_1.write(Unknown Source)
at com.alibaba.fastjson2.writer.ObjectWriter_1.write(Unknown Source)
at com.alibaba.fastjson2.writer.ObjectWriter_1.write(Unknown Source)
....

@lyhu lyhu added the bug Something isn't working label May 22, 2022
wenshao added a commit that referenced this issue May 22, 2022
@wenshao wenshao added this to the 2.0.5 milestone May 23, 2022
@wenshao
Copy link
Member

wenshao commented May 28, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.5
问题已修复,请用新版本

@wenshao wenshao closed this as completed May 28, 2022
@lyhu
Copy link
Author

lyhu commented May 31, 2022

3ks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants