alibaba / alibaba/fastjson2

[BUG] JSONPath.set not working

Open
#2,755 6 comments 0 reactions 0 assignees View on GitHub
bug wontfix
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 问题描述

使用fastjson兼容`JSONPath.set`返回true但没有实际修改成功。使用fastjson 1.x 正常。

### 环境信息

- OS信息: [MacOS 12.7.4 M1 Pro 16 GB]
- JDK信息: [Openjdk 17.0.6]
- 版本信息:[Fastjson 2.0.51]

### 重现步骤

```java
import com.alibaba.fastjson.JSONPath;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue2640_899 {
@Test
public void testWithMutatedBean() {
BeanClass bean = new BeanClass(10, "Original");
System.out.println(JSONPath.set(bean, "$.intValue", 20));
assertEquals(20, bean.getIntValue());
}

static class BeanClass {
private int intValue;
private String stringValue;

public BeanClass(int intValue, String stringValue) {
this.intValue = intValue;
this.stringValue = stringValue;
}

public int getIntValue() {
return intValue;
}

public String getStringValue() {
return stringValue;
}
}
}
```

### 相关日志输出
true

org.opentest4j.AssertionFailedError:
Expected :20
Actual :10

Contributor guide

Open the contributing guide

Research direction

Start with the reported JSONPath.set entry point and reproduce the failure using the provided testWithMutatedBean JUnit test. Compare the returned true value with bean.getIntValue(), and consider the issue resolved when setting $.intValue changes the bean from 10 to 20 as asserted.

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.