Skip to content

[BUG] 序列化 toJSONBytes 时,如果属性为 null,序列化后的 bytes 转 String 时,格式不对,多了 “,” #1603

@DemonJun

Description

@DemonJun

问题描述

简要描述您碰到的问题。

序列化 toJSONBytes 时,如果属性为 null,序列化后的 bytes 转 String 时,格式不对,多了 “,”

环境信息

请填写以下信息:

  • OS信息: Macos 13
  • JDK信息: openjdk 11
  • 版本信息:fastjson2 2.0.33/2.0.34

重现步骤

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

    JSONObject jsonObject =
        JSON.parseObject(
            "{\"deviceId\":\"16584\",\"srcAddress\":\"109.55.156.215\",\"ssssss\":null}");
    byte[] jsonBytes = JSON.toJSONBytes(jsonObject);
    System.out.println(new String(jsonBytes));

期待的正确结果

{"deviceId":"16584","srcAddress":"109.55.156.215"}

相关日志输出

{"deviceId":"16584","srcAddress":"109.55.156.215",}

附加信息

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions