Skip to content
New issue

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

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

Already on GitHub? # to your account

[BUG]NaN反序列化问题 #2300

Closed
tiger2015 opened this issue Mar 7, 2024 · 3 comments
Closed

[BUG]NaN反序列化问题 #2300

tiger2015 opened this issue Mar 7, 2024 · 3 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@tiger2015
Copy link

问题描述

简要描述您碰到的问题。
fastjson2在反序列化Double类型时,遇到{"x":NaN}或者{"x":"NaN"}都不能正确返回序列化,但是fastjson1可以正常反序列化。

环境信息

请填写以下信息:

  • OS信息: [e.g.:Win10]
  • JDK信息: [e.g.:jdk 1.8.0_312]
  • 版本信息:[e.g.:Fastjson2 2.0.34]

重现步骤

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

//可在此输入示例代码
    public static void main(String[] args) {
        String jsonStr = "{\"x\":\"NaN\"}";
        final Data data = JSON.parseObject(jsonStr, Data.class);
        System.out.println(data);
    }

    @lombok.Data
    private static class Data {
        private Double x;
    }

期待的正确结果

对您期望发生的结果进行清晰简洁的描述。
FastJsonTest.Data(x=NaN)

相关日志输出

请复制并粘贴任何相关的日志输出。
Exception in thread "main" com.alibaba.fastjson2.JSONException: illegal fieldName input�, offset 11, character �, line 1, column 12, fastjson-version 2.0.34 {"x":"NaN"}
at com.alibaba.fastjson2.JSONReaderUTF16.readFieldNameHashCode(JSONReaderUTF16.java:1341)
at com.alibaba.fastjson2.reader.ORG_1_1_Data.readObject(Unknown Source)
at com.alibaba.fastjson2.JSON.parseObject(JSON.java:722)

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。

@tiger2015 tiger2015 added the bug Something isn't working label Mar 7, 2024
@Milkdove
Copy link
Contributor

Milkdove commented Mar 7, 2024

我在修复此bug的时候,发现与之前的一个Bug( #1562 )有逻辑上的冲突。

image

NaN以及无穷大、无穷小,不应该被转换成 null 才是合理的,格式化应该只对有限值有效。

@wenshao @yanxutao89

@wenshao
Copy link
Member

wenshao commented Mar 17, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.48-SNAPSHOT/
Double和Float类型已经支持输入NaN,请帮忙用2.0.48-SNAPSHOT版本验证,正式版本预计月底前发布。

@wenshao wenshao added this to the 2.0.48 milestone Mar 17, 2024
@wenshao wenshao added the fixed label Mar 17, 2024
wenshao added a commit that referenced this issue Mar 17, 2024
@wenshao
Copy link
Member

wenshao commented Mar 25, 2024

@wenshao wenshao closed this as completed Mar 25, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

3 participants