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 5a3072d09 fix(java): serialize collections with only null elements in
xlang mode (#2740)
5a3072d09 is described below
commit 5a3072d096dec4cca0222abb0c5b9433679b5ae4
Author: mayuming <[email protected]>
AuthorDate: Fri Oct 10 13:15:42 2025 +0800
fix(java): serialize collections with only null elements in xlang mode
(#2740)
## What does this PR do?
When all collection elements are null, elemClass is set to Object.class
which needs to be handled by classResolver in XLANG mode.
## Related issues
Fixes #2203
<!--
Is there any related issue? If this PR closes them you say say
fix/closes:
-->
## 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.
Delete section if not applicable.
-->
- [ ] 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.
Delete section if not applicable.
-->
---
.../src/main/java/org/apache/fory/resolver/XtypeResolver.java | 2 ++
.../serializer/collection/XlangCollectionSerializerTest.java | 9 +++++++++
2 files changed, 11 insertions(+)
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 258c0df34..309e758bd 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
@@ -550,6 +550,8 @@ public class XtypeResolver extends TypeResolver {
} else {
xtypeId = shareMeta ? Types.COMPATIBLE_STRUCT : Types.STRUCT;
}
+ } else if (cls == Object.class) {
+ return classResolver.getClassInfo(cls);
} else {
Class<Enum> enclosingClass = (Class<Enum>) cls.getEnclosingClass();
if (enclosingClass != null && enclosingClass.isEnum()) {
diff --git
a/java/fory-core/src/test/java/org/apache/fory/serializer/collection/XlangCollectionSerializerTest.java
b/java/fory-core/src/test/java/org/apache/fory/serializer/collection/XlangCollectionSerializerTest.java
index e8f72fd25..d9ea510f0 100644
---
a/java/fory-core/src/test/java/org/apache/fory/serializer/collection/XlangCollectionSerializerTest.java
+++
b/java/fory-core/src/test/java/org/apache/fory/serializer/collection/XlangCollectionSerializerTest.java
@@ -60,4 +60,13 @@ public class XlangCollectionSerializerTest extends
ForyTestBase {
Assert.assertEquals(obj.list1.getClass(), LinkedList.class);
Assert.assertEquals(obj.map1.getClass(), LinkedHashMap.class);
}
+
+ @Test
+ public void testSerializeListWithNullElements() {
+ Fory fory = Fory.builder().withLanguage(Language.XLANG).build();
+ ArrayList<String> strList = new ArrayList<>();
+ strList.add(null);
+ byte[] serialized = fory.serialize(strList);
+ Assert.assertTrue(serialized.length > 0);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]