[BUG] JSON.parseObject with @JSONFIeld not working
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
Based on #1506,Fastjson没有反序列化@JSONFIeld的字段,并且以下的testcase中会不定反序列化A3 or A4。
### 环境信息
- OS信息: [MacOS 12.7.4 M1 Pro 16 GB]
- JDK信息: [Openjdk 17.0.6]
- 版本信息:[Fastjson 2.0.49]
### 重现步骤
```java
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.annotation.JSONField;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class Issue1506Mutated_452 {
@Test
public void test() {
Bean bean = JSON.parseObject("{\"a\":{}}", Bean.class);
assertEquals(A2.class, bean.type);
}
@Test
public void testfj() {
Bean1 bean1 = com.alibaba.fastjson.JSON.parseObject("{\"a\":{}}", Bean1.class);
assertEquals(A2.class, bean1.type);
}
public static class Bean {
private Class type;
public void setA(A a) {
type = a.getClass();
}
public void setA(A1 a) {
type = a.getClass();
}
@JSONField
public void setA(A2 a) {
type = a.getClass();
}
public void setA(A3 a) {
type = a.getClass();
}
public void setA(A4 a) {
type = a.getClass();
}
public void setA(A5 a) {
type = a.getClass();
}
public void setA(A6 a) {
type = a.getClass();
}
}
public static class Bean1 {
private Class type;
public void setA(A a) {
type = a.getClass();
}
public void setA(A1 a) {
type = a.getClass();
}
@com.alibaba.fastjson.annotation.JSONField
public void setA(A2 a) {
type = a.getClass();
}
public void setA(A3 a) {
type = a.getClass();
}
public void setA(A4 a) {
type = a.getClass();
}
public void setA(A5 a) {
type = a.getClass();
}
public void setA(A6 a) {
type = a.getClass();
}
}
public static class A {
}
public static class A1 {
}
public static class A2 {
}
public static class A3 {
}
public static class A4 {
}
public static class A5 {
}
public static class A6 {
}
}
```
### 期待的正确结果
Expected :class issues_20230510.Issue1506Mutated_452$A2
### 相关日志输出
Expected :class issues_20230510.Issue1506Mutated_452$A2
Actual :class issues_20230510.Issue1506Mutated_452$A4
Expected :class issues_20230510.Issue1506Mutated_452$A2
Actual :class issues_20230510.Issue1506Mutated_452$A3
Contributor guide
Research direction
Start by running the Issue1506Mutated_452 reproduction with both JSON.parseObject variants and confirm the A2 versus A3/A4 results. Trace the deserialization entry point and @JSONField handling, then add a regression test showing that the annotated setA(A2) method is selected consistently.
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
- Mostly clear
- Newbie friendliness
- 35/100