[BUG] 升级到 fastjson 2.0.57 反序列化报错
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
最近把 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. 问题代码片段如下:
```java
String response = httpHelper.get(url, heads, REQUEST_TIMEOUT);
ResponseModel resp = null;
try {
resp = JSON.parseObject(response,
new TypeReference>() {
});
} catch (Exception e) {
logger.error("jsonParse for canal config error. Response: {}", response, e);
throw new CanalException("jsonParse for canal config error", e);
}
```
4. 日志打印出来的 JSON String 数据如下:
```json
{"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"}}
```
### 期待的正确结果
正常运行
### 相关日志输出
#### 附加信息
*如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。*
Contributor guide
Research direction
Start with the httpHelper.get response and the JSON.parseObject call shown in the report, using fastjson-2.0.57 and the supplied Java 8 environment. Compare the live response with the logged and copied JSON to isolate why parsing differs after the upgrade. Done means reproducing the failure and confirming normal deserialization of the affected response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100