fastjson2 icon indicating copy to clipboard operation
fastjson2 copied to clipboard

[BUG] JSONPath.set not working

Open Cooperzzy opened this issue 1 year ago • 6 comments

问题描述

使用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

Cooperzzy avatar Jun 28 '24 12:06 Cooperzzy

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

wenshao avatar Jul 07 '24 00:07 wenshao

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

Cooperzzy avatar Jul 07 '24 02:07 Cooperzzy

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

wenshao avatar Jul 07 '24 02:07 wenshao

我们7月3日发送到[email protected]这个邮箱了,请温少查收一下

Cooperzzy avatar Jul 07 '24 02:07 Cooperzzy

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

wenshao avatar Jul 08 '24 00:07 wenshao

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

Cooperzzy avatar Jul 10 '24 11:07 Cooperzzy