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] JSON.toJSONString解析StringBuilder和StringBuffer对象错误 #687

Closed
niganma-aiyou opened this issue Aug 13, 2022 · 2 comments
Closed
Labels
bug Something isn't working
Milestone

Comments

@niganma-aiyou
Copy link

问题描述

JSON.toJSONString解析StringBuilder和StringBuffer对象时,返回值均为 {}。

环境信息

请填写以下信息:

  • JDK信息: 1.8.0_131
  • 版本信息:Fastjson2 2.0.11

重现步骤

    public static void main(String[] args) {
        
        StringBuilder sBuilder = new StringBuilder(" 123 ");
        StringBuffer sBuffer = new StringBuffer(" 123");

        Gson gson = new Gson();

        log.info("原String:{},{},gson: {},{}, fastjson :{},{}",
                sBuilder.toString(),sBuffer.toString(),
                gson.toJson(sBuilder),gson.toJson(sBuffer),
                JSON.toJSONString(sBuilder),JSON.toJSONString(sBuffer));
    }

期待的正确结果

类似gson返回原对象的字符串。

相关日志输出

2022-08-13 15:12:36 707 [INFO] [c=StringUtilsTest] [41] [main] [mainraceId] 原String: 123 , 123,gson: " 123 "," 123", fastjson :{},{}

@niganma-aiyou niganma-aiyou added the bug Something isn't working label Aug 13, 2022
@wenshao wenshao added this to the 2.0.12 milestone Aug 13, 2022
@wenshao
Copy link
Member

wenshao commented Aug 13, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.12-SNAPSHOT/
问题已修复,请帮忙用2.0.12-SNAPSHOT版本验证,2.0.12版本预计在8月21日前发布

@wenshao wenshao closed this as completed Aug 13, 2022
@wenshao
Copy link
Member

wenshao commented Aug 20, 2022

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

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