Skip to content

[BUG] 升级到 fastjson 2.0.57 反序列化报错 #3477

Open
@sunxien

Description

@sunxien

问题描述

最近把 fastjson-2.0.31 升级到 fastjson-2.0.57

一直稳定运行的接口忽然日志报错:com.alibaba.fastjson2.JSONValidException: error, offset 43, char n
报错逻辑发生在 Http 接口返回 JSON String 进行反序列化阶段。

环境信息

请填写以下信息:

  • OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]

  • MacBook Pro M2

  • JDK信息: [e.g.:Openjdk 1.8.0_312]

  • java version "1.8.0_421"

  • Java(TM) SE Runtime Environment (build 1.8.0_421-b09)

  • Java HotSpot(TM) 64-Bit Server VM (build 25.421-b09, mixed mode)

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

  • fastjson-2.0.57

重现步骤

  1. 接口运行期间必然报错;
  2. 诡异的问题是:接口返回的 JSON String 日志打印出来,字符串拷贝出来进行反序列化没问题。只有接口返回的JSON String 进行反序列化必然报错。
  3. 问题代码片段如下:
        String response = httpHelper.get(url, heads, REQUEST_TIMEOUT);
        ResponseModel<CanalConfig> resp = null;
        try {
            resp = JSON.parseObject(response,
                    new TypeReference<ResponseModel<CanalConfig>>() {
                    });
        } catch (Exception e) {
            logger.error("jsonParse for canal config error. Response: {}", response, e);
            throw new CanalException("jsonParse for canal config error", e);
        }
  1. 日志打印出来的 JSON String 数据如下:
{"code":20000,"message":null,"data":{"id":null,"clusterId":null,"canalCluster":null,"serverId":null,"nodeServer":null,"name":null,"content":"mscp","contentMd5":null,"status":null,"modifiedTime":null,"clusterServerId":null,"runningStatus":"0"}}

期待的正确结果

正常运行

相关日志输出

Image

附加信息

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions