This is an automated email from the ASF dual-hosted git repository.

suiliangliang 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 7640dbba fix(java): fix map nested array type serialization codegen 
(#2352)
7640dbba is described below

commit 7640dbba6d194fe734e64920800f3bdafaab2d08
Author: Shawn Yang <[email protected]>
AuthorDate: Wed Jun 18 21:09:01 2025 +0800

    fix(java): fix map nested array type serialization codegen (#2352)
    
    ## What does this PR do?
    
    <!-- Describe the purpose of this PR. -->
    
    ## Related issues
    
    Closes #2348
    
    ## 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.
    -->
---
 .../apache/fory/builder/BaseObjectCodecBuilder.java  | 14 +++++++++++---
 .../serializer/collection/MapSerializersTest.java    | 20 ++++++++++++++++++++
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git 
a/java/fory-core/src/main/java/org/apache/fory/builder/BaseObjectCodecBuilder.java
 
b/java/fory-core/src/main/java/org/apache/fory/builder/BaseObjectCodecBuilder.java
index e1b6b30e..8834ab3f 100644
--- 
a/java/fory-core/src/main/java/org/apache/fory/builder/BaseObjectCodecBuilder.java
+++ 
b/java/fory-core/src/main/java/org/apache/fory/builder/BaseObjectCodecBuilder.java
@@ -666,9 +666,17 @@ public abstract class BaseObjectCodecBuilder extends 
CodecBuilder {
     String name =
         namesForSharedGenericTypeFields.computeIfAbsent(
             typeRef,
-            k ->
-                StringUtils.uncapitalize(typeRef.getRawType().getSimpleName())
-                    + namesForSharedGenericTypeFields.size());
+            k -> {
+              String prefix;
+              if (typeRef.getRawType().isArray()) {
+                Tuple2<Class<?>, Integer> info =
+                    TypeUtils.getArrayComponentInfo(typeRef.getRawType());
+                prefix = info.f0.getSimpleName() + "_arr" + info.f1;
+              } else {
+                prefix = typeRef.getRawType().getSimpleName();
+              }
+              return StringUtils.uncapitalize(prefix) + 
namesForSharedGenericTypeFields.size();
+            });
 
     return getOrCreateField(
         false,
diff --git 
a/java/fory-core/src/test/java/org/apache/fory/serializer/collection/MapSerializersTest.java
 
b/java/fory-core/src/test/java/org/apache/fory/serializer/collection/MapSerializersTest.java
index 7769c790..a9f078c1 100644
--- 
a/java/fory-core/src/test/java/org/apache/fory/serializer/collection/MapSerializersTest.java
+++ 
b/java/fory-core/src/test/java/org/apache/fory/serializer/collection/MapSerializersTest.java
@@ -1028,4 +1028,24 @@ public class MapSerializersTest extends ForyTestBase {
     Object object = fory2.deserialize(bytes);
     assertEquals(object, o);
   }
+
+  @Data
+  @AllArgsConstructor
+  public static class State<K extends Comparable<K>, V> {
+    Map<K, V[]> map;
+  }
+
+  @Test
+  public void testChunkArrayGeneric() {
+    Fory fory = 
Fory.builder().withLanguage(Language.JAVA).requireClassRegistration(false).build();
+    State original = new State(ofHashMap("foo", new String[] {"bar"}));
+    State state = serDe(fory, original);
+    Assert.assertEquals(state.map.get("foo"), new String[] {"bar"});
+
+    State state1 = new State(ofHashMap("foo", null, "bar", new String[] 
{"bar"}));
+    byte[] bytes = fory.serialize(state1);
+    Fory fory2 = builder().withCodegen(false).build();
+    State state2 = (State) fory2.deserialize(bytes);
+    Assert.assertEquals(state2.map.get("bar"), new String[] {"bar"});
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to