alibaba / alibaba/fastjson2

[BUG] JSONArray.toJavaList()不支持Boolean类型到boolean类型的转换,导致赋值错误

Open
#2,934 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

### 问题描述
JSONArray.toJavaList()不支持Boolean类型到boolean类型的转换,导致赋值错误

### 环境信息
*请填写以下信息:*

- OS信息: windows 11
- JDK信息: jdk 1.8
- 版本信息:fastjson2-2.0.23.jar

### 重现步骤
string中为true,解析后为false
```
public class IegnrstOpusJsonTest {

public static class JSONBooleanTest {
@JsonField("is_cooperate")
private boolean cooperate;
}

@Test
public void toJsonList() throws IOException {
List opusResults = null;
String string = "[{\"is_cooperate\":true}]";
opusResults = JSONArray.parseArray(string).toJavaList(JSONBooleanTest.class);
System.out.println(opusResults.toString());
}
}
```
![image](https://github.com/user-attachments/assets/ebb73029-d7d5-4964-be7d-eeb8515c7135)

### 期待的正确结果
应该解析为true

Contributor guide

Open the contributing guide

Research direction

Start at JSONArray.toJavaList() and reproduce the supplied toJavaList test using JSONBooleanTest and its @JsonField mapping. Use the string containing true as the test input and verify that the resulting boolean field is true; that passing behavior is the done criterion.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.