fastjson2
fastjson2 copied to clipboard
[BUG] JSONPath.set not working
问题描述
使用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]
重现步骤
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
这个没有setter方法,不兼容是对的
明白了,感谢温少。我们前几天给您邮箱发了一封论文合作的邮件,想邀请您作为文章的共同作者。不知道您是否有兴趣参与?
好的,你先发给我看下内容哈
我们7月3日发送到[email protected]这个邮箱了,请温少查收一下
已经回复,非常有意思的一个工作,很乐意参与一起完成。
非常感谢温少支持,刚给您发送了follow up的邮件,请查收一下