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]基于 float 类型的 json 序列化 Float.NaN/INFINITY/NEGATIVE_INFINITY 不再以 null 进行输出 #423

Closed
magical1989 opened this issue Jun 6, 2022 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@magical1989
Copy link
Contributor

问题描述

基于 float 类型的 json 序列化 Float.NaN/INFINITY/NEGATIVE_INFINITY 不再以 null 进行输出

环境信息

  • 版本信息:[e.g.:Fastjson2 2.0.4]

重现步骤

如何操作可以重现该问题:
想使用新版本 fastjson2 来替换原有 fastjson(基于您的性能测试和对内部部分数据进行压测后,效果的确非常惊艳)
发现在 float 类型 NaN 时,与原来 fastjson 1 版本时期的语义存在差异。
示例代码如下:

    public static void main(String[] args) {
        float[] a = {0f, 0.0f, 0.1f, Float.NaN, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY};
        System.out.println(JSON.toJSONString(a));
    }

[0.0,0.0,0.1,NaN,Infinity,-Infinity],这是对应的输出。

研读您的代码后发现,RyuFloat 中基于 float 的实现的确会按照上述演示的业务进行输出。
个人理解,您这里是想表达出 float 类型在 Java 中存在的情况会有 Float.NaN/INFINITY/NEGATIVE_INFINITY 这三种例外的情况。
但是从 json 的角度(json.org)上并没有这类值的关键字,这里是否保留 fastjson 1 的全 null 处理会更加合理呢?或至少留下一个 Feature 枚举提供可选。

@magical1989 magical1989 added the bug Something isn't working label Jun 6, 2022
@wenshao wenshao added this to the 2.0.7 milestone Jun 6, 2022
@wenshao
Copy link
Member

wenshao commented Jun 6, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.7-SNAPSHOT/

问题已经修,你用2.0.7-SNAPSHOT先验证一下

@magical1989
Copy link
Contributor Author

magical1989 commented Jun 7, 2022

已经验证过了,对于 @wenshao 您的工作效率感到非常惊艳。
chk 了您的修订,同时修改了 double,并做了对应 test,非常优秀。
a9a87a4

@magical1989 magical1989 changed the title [BUG] [BUG]基于 float 类型的 json 序列化 Float.NaN/INFINITY/NEGATIVE_INFINITY 不再以 null 进行输出 Jun 7, 2022
@wenshao
Copy link
Member

wenshao commented Jun 11, 2022

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

@wenshao wenshao closed this as completed Jun 11, 2022
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