[BUG]同时继承了class跟interface,且都有同名方法时,序列化有概率有优先获取到接口中的方法,导致序列化失败
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
[BUG]同时继承了class跟interface,且都有同名方法时,序列化有概率有优先获取到接口中的方法,导致序列化失败报java.lang.AbstractMethodError异常
### 环境信息
*请填写以下信息:*
- OS信息: [Red Hat 9.3.1-2]
- JDK信息: [Java(TM) SE Runtime Environment (build 1.8.0_251-b08)]
- 版本信息:[Fastjson2 2.0.26]
### 重现步骤
*如何操作可以重现该问题:*
当一个类同时继承了class跟interface,且都包括同样签名的方法时, 不能优先获取到class里面的同名方法,导致序列化失败
```java
package sample;
import lombok.Data;
@Data
public class Test4 {
private Long userId;
private Long testValue;
}
package sample;
public interface Test3 {
Long getUserId() ;
}
package sample;
import com.alibaba.fastjson.JSON;
public class Test extends Test4 implements Test3{
public static void main(String[] args) {
Test tt = new Test();
tt.setTestValue(2L);
JSON.toJSONString(tt);
}
}
```
### 期待的正确结果
能够正常的进行序列化
### 相关日志输出
java.lang.AbstractMethodError: sample.Test.getUserId()Ljava/lang/Long;:
at com.alibaba.fastjson2.writer.ObjectWriter_31.write(Unknown Source)
at com.alibaba.fastjson2.JSON.toJSONString(JSON.java:2258)
#### 附加信息
Contributor guide
Research direction
Start by reproducing the sample Test4, Test3, and Test classes with Java 8 and Fastjson2 2.0.26, then inspect the serialization path shown in JSON.toJSONString at JSON.java:2258 and the generated ObjectWriter_31 stack frame. Done means the class implementing the interface serializes successfully without AbstractMethodError.
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
- 45/100