This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git
The following commit(s) were added to refs/heads/main by this push:
new 9d87f2b8e fix(java): fix decode classdef for abstract classes (#2462)
9d87f2b8e is described below
commit 9d87f2b8e654dbd7af5d2b5bd54f3fdf322de6c0
Author: Shawn Yang <[email protected]>
AuthorDate: Wed Aug 13 14:05:48 2025 +0800
fix(java): fix decode classdef for abstract classes (#2462)
<!--
**Thanks for contributing to Fory.**
**If this is your first time opening a PR on fory, you can refer to
[CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).**
Contribution Checklist
- The **Apache Fory** community has requirements on the naming of pr
titles. You can also find instructions in
[CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).
- Fory has a strong focus on performance. If the PR you submit will have
an impact on performance, please benchmark it first and provide the
benchmark result here.
-->
## What does this PR do?
<!-- Describe the purpose of this PR. -->
## Related issues
Closes #2461
## Does this PR introduce any user-facing change?
<!--
If any user-facing interface changes, please [open an
issue](https://github.com/apache/fory/issues/new/choose) describing the
need to do so and update the document if necessary.
-->
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
<!--
When the PR has an impact on performance (if you don't know whether the
PR will have an impact on performance, you can submit the PR first, and
if it will have impact on performance, the code reviewer will explain
it), be sure to attach a benchmark data here.
-->
---
.../java/org/apache/fory/meta/ClassDefDecoder.java | 2 +-
.../org/apache/fory/meta/ClassDefEncoderTest.java | 51 ++++++++++++++++++++++
2 files changed, 52 insertions(+), 1 deletion(-)
diff --git
a/java/fory-core/src/main/java/org/apache/fory/meta/ClassDefDecoder.java
b/java/fory-core/src/main/java/org/apache/fory/meta/ClassDefDecoder.java
index 5a6ec5933..1c9b41607 100644
--- a/java/fory-core/src/main/java/org/apache/fory/meta/ClassDefDecoder.java
+++ b/java/fory-core/src/main/java/org/apache/fory/meta/ClassDefDecoder.java
@@ -87,7 +87,7 @@ class ClassDefDecoder {
classSpec = new
ClassSpec(NonexistentClass.NonexistentMetaShared.class);
className = classSpec.entireClassName;
} else {
- Class<?> cls = resolver.getClassInfo(registeredId).getCls();
+ Class<?> cls = resolver.getRegisteredClass(registeredId);
className = cls.getName();
classSpec = new ClassSpec(cls);
}
diff --git
a/java/fory-core/src/test/java/org/apache/fory/meta/ClassDefEncoderTest.java
b/java/fory-core/src/test/java/org/apache/fory/meta/ClassDefEncoderTest.java
index eec203fd9..170c5a50e 100644
--- a/java/fory-core/src/test/java/org/apache/fory/meta/ClassDefEncoderTest.java
+++ b/java/fory-core/src/test/java/org/apache/fory/meta/ClassDefEncoderTest.java
@@ -26,6 +26,7 @@ import java.io.Serializable;
import java.util.List;
import lombok.Data;
import org.apache.fory.Fory;
+import org.apache.fory.config.CompatibleMode;
import org.apache.fory.config.Language;
import org.apache.fory.memory.MemoryBuffer;
import org.apache.fory.test.bean.BeanA;
@@ -119,4 +120,54 @@ public class ClassDefEncoderTest {
Assert.assertEquals(header & ClassDef.COMPRESS_META_FLAG,
ClassDef.COMPRESS_META_FLAG);
Assert.assertEquals(header & ClassDef.HAS_FIELDS_META_FLAG, 0);
}
+
+ @Test
+ public void testAbstractParentClass() {
+ Fory fory0 =
+ Fory.builder()
+ .withMetaShare(true)
+ .withScopedMetaShare(true)
+ .withCompatibleMode(CompatibleMode.COMPATIBLE)
+ .requireClassRegistration(false)
+ .build();
+ Fory fory1 =
+ Fory.builder()
+ .withMetaShare(true)
+ .withScopedMetaShare(true)
+ .withCompatibleMode(CompatibleMode.COMPATIBLE)
+ .build();
+ fory1.register(BaseAbstractClass.class);
+ fory1.register(ChildClass.class);
+ for (Fory fory : new Fory[] {fory0, fory1}) {
+ ClassDef classDef = ClassDef.buildClassDef(fory, ChildClass.class);
+ ClassDef classDef1 =
+ ClassDef.readClassDef(fory,
MemoryBuffer.fromByteArray(classDef.getEncoded()));
+ Assert.assertEquals(classDef, classDef1);
+ ChildClass c = new ChildClass();
+ c.setId("123");
+ c.setName("test");
+ byte[] serialized = fory.serialize(c);
+ ChildClass c1 = fory.deserialize(serialized, ChildClass.class);
+ Assert.assertEquals(c1.getId(), "123");
+ Assert.assertEquals(c1.getName(), "test");
+ }
+ }
+
+ @Data
+ public abstract static class BaseAbstractClass {
+ private String id;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+ }
+
+ @Data
+ public static class ChildClass extends BaseAbstractClass {
+ private String name;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]