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 7c945198 feat(java): support multi-dimensional array field
serialization in xlang meta shared mode (#2314)
7c945198 is described below
commit 7c945198bc33fb96b35ca75819eacad8bc7f7139
Author: OmCheeLin <[email protected]>
AuthorDate: Mon Jun 9 22:42:22 2025 +0800
feat(java): support multi-dimensional array field serialization in xlang
meta shared mode (#2314)
## What does this PR do?
support multi-dimensional array field serialization in xlang meta shared
mode
## Related issues
#2277
## Does this PR introduce any user-facing change?
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
---------
Co-authored-by: Shawn Yang <[email protected]>
---
java/fory-core/src/main/java/org/apache/fory/meta/ClassDef.java | 6 ++++++
.../src/main/java/org/apache/fory/resolver/XtypeResolver.java | 2 +-
.../src/test/java/org/apache/fory/xlang/MetaSharedXlangTest.java | 3 +--
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/java/fory-core/src/main/java/org/apache/fory/meta/ClassDef.java
b/java/fory-core/src/main/java/org/apache/fory/meta/ClassDef.java
index f5c9e41f..ff3a46ff 100644
--- a/java/fory-core/src/main/java/org/apache/fory/meta/ClassDef.java
+++ b/java/fory-core/src/main/java/org/apache/fory/meta/ClassDef.java
@@ -843,6 +843,9 @@ public class ClassDef implements Serializable {
@Override
public TypeRef<?> toTypeToken(TypeResolver classResolver, TypeRef<?>
declared) {
+ while (declared != null && declared.isArray()) {
+ declared = declared.getComponentType();
+ }
TypeRef<?> componentTypeRef = componentType.toTypeToken(classResolver,
declared);
Class<?> componentRawType = componentTypeRef.getRawType();
if (NonexistentClass.class.isAssignableFrom(componentRawType)) {
@@ -993,6 +996,9 @@ public class ClassDef implements Serializable {
}
if (rawType.isArray()) {
Class<?> elemType = rawType.getComponentType();
+ while (elemType.isArray()) {
+ elemType = elemType.getComponentType();
+ }
if (isXlang && !elemType.isPrimitive()) {
return new CollectionFieldType(
xtypeId,
diff --git
a/java/fory-core/src/main/java/org/apache/fory/resolver/XtypeResolver.java
b/java/fory-core/src/main/java/org/apache/fory/resolver/XtypeResolver.java
index 28e25d8d..4cd2bfdf 100644
--- a/java/fory-core/src/main/java/org/apache/fory/resolver/XtypeResolver.java
+++ b/java/fory-core/src/main/java/org/apache/fory/resolver/XtypeResolver.java
@@ -431,7 +431,7 @@ public class XtypeResolver implements TypeResolver {
serializer = getCollectionSerializer(cls);
}
xtypeId = Types.LIST;
- } else if (cls.isArray() &&
!TypeUtils.getArrayComponent(cls).isPrimitive()) {
+ } else if (cls.isArray() && !cls.getComponentType().isPrimitive()) {
serializer = new ArraySerializers.ObjectArraySerializer(fory, cls);
xtypeId = Types.LIST;
} else if (classResolver.isMap(cls)) {
diff --git
a/java/fory-core/src/test/java/org/apache/fory/xlang/MetaSharedXlangTest.java
b/java/fory-core/src/test/java/org/apache/fory/xlang/MetaSharedXlangTest.java
index 0528c834..903f63f6 100644
---
a/java/fory-core/src/test/java/org/apache/fory/xlang/MetaSharedXlangTest.java
+++
b/java/fory-core/src/test/java/org/apache/fory/xlang/MetaSharedXlangTest.java
@@ -62,7 +62,7 @@ public class MetaSharedXlangTest extends ForyTestBase {
int[][] arr;
}
- // @Test
+ @Test
public void testMDArrayField() {
Fory fory =
Fory.builder()
@@ -70,7 +70,6 @@ public class MetaSharedXlangTest extends ForyTestBase {
.withCodegen(false)
.withCompatibleMode(CompatibleMode.COMPATIBLE)
.build();
- // TODO support multi-dimensional array serialization
fory.register(MDArrayFieldStruct.class, "example.a");
MDArrayFieldStruct s = new MDArrayFieldStruct();
s.arr = new int[][] {{1, 2}, {3, 4}};
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]