故障排除
本页介绍常见问题及其解决方案。
类不一致和类版本检查
如果你创建 Fory 时没有将 CompatibleMode 设置为 org.apache.fory.config.CompatibleMode.COMPATIBLE,并且遇到奇怪的序列化错误,这可能是由于序列化端和反序列化端之间的类不一致造成的。
在这种情况下,你可以调用 ForyBuilder#withClassVersionCheck 来创建 Fory 以验证它。如果反序列化抛出 org.apache.fory.exception.ClassNotCompatibleException,则表示类不一致,你应该使用 ForyBuilder#withCompatibleMode(CompatibleMode.COMPATIBLE) 创建 Fory。
// 启用类版本检查以诊断问题
Fory fory = Fory.builder()
.withLanguage(Language.JAVA)
.withClassVersionCheck(true)
.build();
// 如果抛出 ClassNotCompatibleException,使用兼容模式
Fory fory = Fory.builder()
.withLanguage(Language.JAVA)
.withCompatibleMode(CompatibleMode.COMPATIBLE)
.build();