alibaba / alibaba/fastjson2

[BUG] 字段上@JSONField的JSONWriter.Feature.WriteNullBooleanAsFalse不生效

Open
#3,759 1 comment 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

### 问题描述
fastjson2字段上注解JSONField(serializeFeatures = JSONWriter.Feature.WriteNullBooleanAsFalse)不生效。

### 环境信息
jdk21 , fastjson2.0.58

### 重现步骤

```java
@Data
public class TestDTO{
@JSONField(serializeFeatures = JSONWriter.Feature.WriteNullBooleanAsFalse)
private Boolean booleanField;
private String otherField="";
}

```
JSON.toJSONString(new TestDTO());

### 期待的正确结果
```json
{
"booleanField": false,
"otherField": ""
}
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the supplied TestDTO on JDK 21 and fastjson2 2.0.58, calling JSON.toJSONString(new TestDTO()). Trace how JSONField.serializeFeatures handles JSONWriter.Feature.WriteNullBooleanAsFalse. Done means the output includes booleanField as false and preserves otherField as an empty string.

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.