[BUG]FieldBased后 不会调用public setter 进行赋值
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
当设置JSONReader.Feature.FieldBased
不会调用public的setter进行复制了.
即使没有合适private的成员,也不调用合适的setter.
### 环境信息
*请填写以下信息:*
- OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]
- JDK信息: [e.g.:Openjdk 1.8.0_312]
- 版本信息:[e.g.:Fastjson2 2.0.41]
### 重现步骤
*如何操作可以重现该问题:*
```java
import org.junit.Test;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONReader;
public class JSONFieldBasedTest {
@Test
public void test() {
String json = "{\"id\":101,\"data\":\"1\"}";
DATA data = JSON.parseObject(json,DATA.class,JSONReader.Feature.FieldBased);
System.out.println(data.mdata);
}
public static enum EnumType{
A,B;
public static EnumType parse(String str) {
return "1".equals(str)?A:B;
}
}
public static class DATA{
int id;
EnumType mdata;
public String getData() {
return mdata==EnumType.A?"1":"2";
}
public void setData(String val) {
System.out.println("in parse type");
mdata = EnumType.parse(val);
}
}
}
```
Contributor guide
Research direction
Start by running the JSONFieldBasedTest example through JSON.parseObject with JSONReader.Feature.FieldBased and observe whether setData is invoked. Trace the FieldBased deserialization path for the DATA example; done means the public setter handles data when no suitable private member is available, producing EnumType.A.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100