fastjson2 icon indicating copy to clipboard operation
fastjson2 copied to clipboard

[BUG] Abnormal serialization with JSON.toJSONBytes

Open Cooperzzy opened this issue 1 year ago • 5 comments

问题描述

JSON.toJSONBytes后序列化异常

环境信息

  • OS信息: [MacOS 12.7.4 M1 Pro 16 GB]
  • JDK信息: [Openjdk 17.0.6]
  • 版本信息:[Fastjson2-2.0.49]

重现步骤


import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue2128Mutated {
    @Test
    public void test() {
        String str = "{\"amt\":22.12}";
        assertEquals(JSON.toJSONString(JSON.parseObject(str)),JSON.toJSONString(JSON.toJSONBytes(str)));
    }
}


期待的正确结果

toJSONBytes后正常序列化

相关日志输出

Expected :{"amt":22.12} Actual :[34,123,92,34,97,109,116,92,34,58,50,50,46,49,50,125,34]

Cooperzzy avatar May 08 '24 09:05 Cooperzzy

感谢反馈了这么多问题,请问是实际业务场景升级遇到还是构建测试发现的?

wenshao avatar May 08 '24 09:05 wenshao

是一项研究性质的research,通过自动化测试发现潜在问题。Fastjson作为阿里著名开源项目,我们尝试在此之上进行了这项工作。所有测试都经过二次人工审查,也希望为开源项目贡献反馈。感谢温少支持。

Cooperzzy avatar May 08 '24 11:05 Cooperzzy

非常欢迎,但由于反馈的问题较多,工作量的原因,本周日(5月12日)发布的版本可能来不及全部修复。

wenshao avatar May 08 '24 19:05 wenshao

这个testcase构造的可能不对,比如应该是这样:

        String str = "{\"amt\":22.12}";
        assertEquals(
                JSON.toJSONString(JSON.parseObject(str)),
                JSON.toJSONString(JSON.parseObject(str.getBytes(StandardCharsets.UTF_8)))
        );

wenshao avatar May 08 '24 23:05 wenshao

收到,辛苦温少

Cooperzzy avatar May 09 '24 06:05 Cooperzzy