alibaba / fastjson2

🚄 FASTJSON2 is a Java JSON library with excellent performance.
Apache License 2.0
3.61k stars 474 forks source link

[BUG] JSONPath.set not working #2755

Open Cooper-Zhong opened 3 weeks ago

Cooper-Zhong commented 3 weeks ago

问题描述

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

环境信息

重现步骤

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

wenshao commented 1 week ago

这个没有setter方法,不兼容是对的

Cooper-Zhong commented 1 week ago

明白了,感谢温少。我们前几天给您邮箱发了一封论文合作的邮件,想邀请您作为文章的共同作者。不知道您是否有兴趣参与?

wenshao commented 1 week ago

好的,你先发给我看下内容哈

Cooper-Zhong commented 1 week ago

我们7月3日发送到shaojin.wensj@alibaba-inc.com这个邮箱了,请温少查收一下

wenshao commented 1 week ago

已经回复,非常有意思的一个工作,很乐意参与一起完成。

Cooper-Zhong commented 1 week ago

非常感谢温少支持,刚给您发送了follow up的邮件,请查收一下