Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

序列化时会调用对象的所有get方法,并且是根据get方法去解析属性的吗 #4525

Open
wpfxff opened this issue Jul 29, 2024 · 0 comments

Comments

@wpfxff
Copy link

wpfxff commented Jul 29, 2024

问题描述
fastjson 序列化时,会调用所有get开头并且是驼峰命名的方法,并且是根据get方法去解析对象属性的吗?(是设计如此吗)
User对象没有创建test属性,但是输出结果根据getTest方法解析到了test属性

环境信息
请填写以下信息:

OS信息: window10
JDK信息: 1.8
版本信息:所有版本(fastjson fastjson2)
重现步骤
public static void main(String[] args) {
User user = new User();
user.setName("test");
System.out.println(JSON.toJSONString(user));
}
class User{
private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getTest(){
System.out.println("测试调用自定义get方法");
return "测试调用自定义get方法";
}

public String getdev(){
System.out.println("测试");
return "测试";
}
}

输出结果
测试调用自定义get方法
{"name":"test","test":"测试调用自定义get方法"}

期待的正确结果
期望只输出对应字段的序列化结果,目前测试了市面上的几款json工具,好像只有fastjson、fastjson2会出现此问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant