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]序列化对象时JSONWriter.Feature.BrowserCompatible对属性List<Long>类型无效 #1742

Closed
zh112500 opened this issue Aug 15, 2023 · 6 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@zh112500
Copy link

问题描述

序列化对象时JSONWriter.Feature.BrowserCompatible对属性List<Long>类型无效

环境信息

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

重现步骤

  @Getter
  public static class TestFastJson {
      private long a = 1443605444282772302L;
      private List\<Long\> b = new ArrayList\<Long\>() {{
          add(1443605444282772302L);
          add(1443605444282772303L);
          add(1443605444282772304L);
      }};
  }

  public static void main(String[] args) {
      System.out.println(JSON.toJSONString(new TestFastJson(), JSONWriter.Feature.BrowserCompatible));
  }

期待的正确结果

{"a":"1443605444282772302","b":[“1443605444282772302”,“1443605444282772303”,“1443605444282772304”]}。

相关日志输出

{"a":"1443605444282772302","b":[1443605444282772302,1443605444282772303,1443605444282772304]}

@zh112500 zh112500 added the bug Something isn't working label Aug 15, 2023
@zh112500 zh112500 changed the title [BUG] [BUG]序列化对象时JSONWriter.Feature.BrowserCompatible对属性List<Long>类型无效 Aug 15, 2023
@wenshao wenshao added this to the 2.0.40 milestone Aug 15, 2023
@wenshao
Copy link
Member

wenshao commented Aug 17, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.40-SNAPSHOT/
请帮忙用2.0.40-SNAPSHOT验证问题是否已经修复

@zh112500
Copy link
Author

已解决

@wenshao wenshao added the fixed label Aug 18, 2023
@zh112500 zh112500 reopened this Aug 21, 2023
@zh112500
Copy link
Author

zh112500 commented Aug 21, 2023

@Getter
public static class TestFastJson {
    private long bLong = 1443605444282772302L;
    private List<Long> list = new ArrayList<Long>() {{
        add(1443605444282772302L);
        add(1443605444282772303L);
        add(1L);
    }};
    private long[] array = new long[]{
            1443605444282772302L, 1443605444282772303L, 1L
    };
}

@org.junit.jupiter.api.Test
public void testFastJson() {
    Object obj = new TestFastJson();
    System.out.println(JSON.toJSONString(obj, JSONWriter.Feature.BrowserCompatible));

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    JSON.writeTo(baos, obj, "", new Filter[0], JSONWriter.Feature.BrowserCompatible);
    System.out.println(baos);
}

输出结果:

image

|| (browserCompatible && v <= 9007199254740991L && v >= -9007199254740991L);

|| (browserCompatible && v <= 9007199254740991L && v >= -9007199254740991L);

上面两处好像逻辑错了吧
@wenshao

@GabrielHwang
Copy link
Contributor

是应该全都 !(v <= 9007199254740991L && v >= -9007199254740991L);

@wenshao wenshao modified the milestones: 2.0.40, 2.0.41 Sep 3, 2023
@wenshao
Copy link
Member

wenshao commented Sep 3, 2023

https://github.com/alibaba/fastjson2/releases/tag/2.0.40
请用新版本,这个版本部分修复。完整修复预计在2.0.41版本

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.41-SNAPSHOT/
请帮忙用2.0.41-SNAPSHOT验证问题是否已经完全修复

@wenshao
Copy link
Member

wenshao commented Oct 6, 2023

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

No branches or pull requests

3 participants