alibaba / alibaba/fastjson2

[BUG]:fastjson2 parseObject 会将空字符串 Empty String成功转成String[] 而不是失败

Open
#3,132 0 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

### 问题描述
JSONObject.parseObject会成功的将一个空字符串转换为String[],预期应该出现Exception。

### 环境信息

- 版本信息:[e.g.:Fastjson2 2.0.53]

### 重现步骤
```java
import com.alibaba.fastjson2.JSONObject;

import java.util.Arrays;

public class Main {

public static void main(String[] args) {

var str = "{\"xxx\": \"\"}";

var fastjson = JSONObject.parseObject(str, TestObject.class);

System.out.println(fastjson);
System.out.println(Arrays.toString(fastjson.xxx()));
}
}

record TestObject(String[] xxx) {

}
```

### 期待的正确结果
预期应该失败,不应该转换成功。

### 相关日志输出
TestObject[xxx=null]
null

#### 附加信息
[相关代码](https://github.com/alibaba/fastjson2/blob/2b0efeee501f9fc6ab215910a51491edfe43784e/core/src/main/java/com/alibaba/fastjson2/JSONReader.java#L1807)

Contributor guide

Open the contributing guide

Research direction

Start with the linked location in core/src/main/java/com/alibaba/fastjson2/JSONReader.java around line 1807, then run the provided Main reproduction using JSONObject.parseObject and TestObject. Add a regression test covering an empty string converted to String[], and verify that parsing fails with an exception rather than producing a null array.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.