This repository was archived by the owner on Oct 23, 2024. It is now read-only.
This repository was archived by the owner on Oct 23, 2024. It is now read-only.
Error: jdk1.8下asm系列化有缺省方法的接口 #289
Closed
Description
jdk1.8支持接口缺省方法,JavaBeanSerializer系列化正常,使用ASMJavaBeanSerializer则报错。
- 最简单的方法,不用asm:
- ParserConfig.getGlobalInstance().setAsmEnable(false);
- SerializeConfig.getGlobalInstance().setAsmEnable(false);
- 用asm,如何解决?
测试代码(每个类作单独文件)
package xx;
public interface Mixinable {
default long getCompanyId() {
return 0;
}
default void setCompanyId(long companyId) {
}
}
public class A implements Mixinable {
}
public class TestAsm {
public static void main(String[] args) {
A a = new A();
//toJSONString报错
String json = JSON.toJSONString(a);
//parse也将报错
a = (A)JSON.parse(json);
}
}
错误信息
Exception in thread "main" java.lang.IncompatibleClassChangeError: Found interface xx.Mixinable, but class was expected
at Serializer_1.write1(Unknown Source)
at Serializer_1.write(Unknown Source)
at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:361)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:393)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:381)
原因分析:A中未实现Mixinable的get/setCompanyId方法,导致asm writer的method属于接口(本应属于A),调用错误。
A不想再实现Mixinable中的缺省方法,因为想要A实现多继承,不论Mixinable缺省接口怎么增减,A不变。
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
bug fixed for issue 289. #289
wenshao commentedon Apr 15, 2016
已经实现,1.2.9就会支持
bug fixed for compatible jdk8 default method. issue #289 #830 #935
bug fixed for issue 289. alibaba#289
bug fixed for compatible jdk8 default method. issue alibaba#289 aliba…