[BUG] 序列化时会调用对象的所有get方法,并且是根据get方法去解析属性的吗
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
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方法
{"dev":"测试","name":"test","test":"测试调用自定义get方法"}
### 期待的正确结果
*期望只输出对应字段的序列化结果,目前测试了市面上的几款json工具,好像只有fastjson、fastjson2会出现此问题*
Contributor guide
Research direction
Reproduce the report with the shown User class and JSON.toJSONString(user), observing calls to getTest and getdev and the emitted properties. Then inspect the serialization property-discovery entry point; done means the expected getter and property behavior is decided and covered by an appropriate regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100