alibaba / alibaba/fastjson2

[BUG]反序列化错误,json字符串字段顺序影响反序列化结果

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

```import java.math.BigDecimal;
public class DeserializeModel {

private BigDecimal amt;

private Boolean flag;

public BigDecimal getAmt() {
return amt;
}

public void setAmt(BigDecimal amt) {
this.amt = amt;
}

public Boolean getFlag() {
return flag;
}

public void setFlag(Boolean flag) {
this.flag = flag;
}
}

```
@Test
void fastJsonTest() {
String str = "{\"amt\":null,\"flag\":false}"; // 反序列化错误 {}
// String str = "{\"flag\":false, \"amt\":null}"; // 正常 {"flag":false}
DeserializeModel deserializeModel = JSON.parseObject(str, DeserializeModel.class);
System.out.println(JSON.toJSONString(deserializeModel));
}

Contributor guide

Open the contributing guide

Research direction

Start with the DeserializeModel and fastJsonTest reproduction in the issue, running both JSON field orders to confirm the differing serialized results. Trace the deserialization path responsible for BigDecimal null and Boolean false values, then add a regression test showing that field order does not change the result.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.