alibaba / alibaba/fastjson2

[BUG]fastjson2中set方法连续多次设置数组,仅第一次set有效

Open
#7,681 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中JSONPath set方法连续两次设置数组,仅第一次有效

### 环境信息

- OS信息:
- JDK信息:Openjdk21
- 版本信息:Fastjson2-2.0.61

### 重现步骤

```java
JSONObject row = new JSONObject();

JSONObject aaa1 = new JSONObject();
aaa1.put("import_id","250922223357263690");
JSONObject bbb1 = new JSONObject();
bbb1.put("import_id","250922223357263690");

JSONPath.set(row,"data.aaa[0]",aaa1);
JSONPath.set(row,"data.bbb[0]",bbb1);
System.out.println("fastjson2 data:"+JSON.toJSON(row));

```

### 期待的正确结果
预期:{"data":{"aaa":[{"import_id":"111"}],"bbb":[{"import_id":"222"}]}}
目前:{"data":{"aaa":[{"import_id":"111"}]}}

JSONPath.set(row,"data.bbb[0]",bbb1); 貌似未生效,也未报错

Contributor guide

Open the contributing guide

Research direction

Start at the JSONPath.set entry point and reproduce the issue with the two consecutive array assignments shown in the report. Trace how the data object is created or updated for each path, then add a regression test covering both assignments. Done means data.aaa[0] and data.bbb[0] are both present after the calls.

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
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.