alibaba / alibaba/fastjson2

Json串的节点为String,转换类的变量为其他类变量,转换出错,其他字段未正确解析,也未抛出异常。

Open
#593 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 问题描述
Json串的节点为String,转换类的变量为其他类变量,转换出错,其他字段未正确解析,也未抛出异常。

### 环境信息
- JDK信息: [e.g.:corretto-1.8.0_342]
- 版本信息:[e.g.:Fastjson2 2.0.10]

### 重现步骤
1. 使用JSON.parseObject 方法
2. 输入 "{\"name\":\"张三\",\"testExtData\":\"{}\",\"age\":18}" 数据
3. 未出现异常,testExtData后面数据均丢失.Test(name=张三, age=null, testExtData=TestExtData(sex=null))
```java
@Data
public class Test implements Serializable{

String name;

String age;

/**
* 字段扩展 N
*/
TestExtData testExtData;

}
@Data
public class TestExtData implements Serializable {
String sex;
}

void testJson() {
String json = "{\"name\":\"张三\",\"testExtData\":\"{}\",\"age\":18}";
Test test = new Test();
try {
test = JSON.parseObject(json, Test.class);
} catch (Exception e) {
System.out.println(e);
}
}
```

### 期待的正确结果
Test(name=张三, age=18, testExtData=TestExtData(sex=null))

### 相关日志输出
未有异常输出

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue through JSON.parseObject using the Test and TestExtData classes and the JSON shown in the report. Inspect how the parser handles a string-valued testExtData field when the target type is an object, and verify that age is still parsed and the expected Test result is produced without silently losing later fields.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.