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/fury.git


The following commit(s) were added to refs/heads/main by this push:
     new a7c45f34 fix(java): fix nested map serialization codegen (#1713)
a7c45f34 is described below

commit a7c45f344bf65bea73e2f0cb9aeb17a3698bec1f
Author: Shawn Yang <shawn.ck.y...@gmail.com>
AuthorDate: Sun Jun 30 19:05:19 2024 +0800

    fix(java): fix nested map serialization codegen (#1713)
    
    ## What does this PR do?
    
    Closes #1700
    
    ## Related issues
    
    
    
    
    ## Does this PR introduce any user-facing change?
    
    <!--
    If any user-facing interface changes, please [open an
    issue](https://github.com/apache/fury/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.
    -->
---
 .../org/apache/fury/benchmark/state/JsonTest.java  | 32 ++++++++++++++++++++--
 .../fury/builder/BaseObjectCodecBuilder.java       |  2 +-
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git 
a/java/benchmark/src/test/java/org/apache/fury/benchmark/state/JsonTest.java 
b/java/benchmark/src/test/java/org/apache/fury/benchmark/state/JsonTest.java
index c640b021..6f369dac 100644
--- a/java/benchmark/src/test/java/org/apache/fury/benchmark/state/JsonTest.java
+++ b/java/benchmark/src/test/java/org/apache/fury/benchmark/state/JsonTest.java
@@ -20,23 +20,44 @@
 package org.apache.fury.benchmark.state;
 
 import com.alibaba.fastjson2.JSONObject;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
+import java.util.List;
 import org.apache.fury.Fury;
+import org.apache.fury.collection.Collections;
 import org.apache.fury.config.CompatibleMode;
 import org.apache.fury.config.Language;
 import org.testng.Assert;
+import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
 public class JsonTest {
   public static class DemoResponse {
     private JSONObject json;
+    private List<JSONObject> objects;
 
     public DemoResponse(JSONObject json) {
       this.json = json;
+      objects = Collections.ofArrayList(json);
     }
   }
 
-  @Test
-  public void testSerializeJson() {
+  @DataProvider
+  public static Object[][] config() {
+    return Sets.cartesianProduct(
+            ImmutableSet.of(true, false), // referenceTracking
+            ImmutableSet.of(true, false), // compatible mode
+            ImmutableSet.of(true, false), // scoped meta share mode
+            ImmutableSet.of(true, false) // fury enable codegen
+            )
+        .stream()
+        .map(List::toArray)
+        .toArray(Object[][]::new);
+  }
+
+  @Test(dataProvider = "config")
+  public void testSerializeJson(
+      boolean trackingRef, boolean compatible, boolean scoped, boolean 
codegen) {
     // For issue: https://github.com/apache/fury/issues/1604
     JSONObject jsonObject = new JSONObject();
     jsonObject.put("k1", "v1");
@@ -46,12 +67,17 @@ public class JsonTest {
         Fury.builder()
             .withLanguage(Language.JAVA)
             .requireClassRegistration(false)
-            .withRefTracking(true)
+            .withRefTracking(trackingRef)
+            .withCompatibleMode(
+                compatible ? CompatibleMode.COMPATIBLE : 
CompatibleMode.SCHEMA_CONSISTENT)
+            .withScopedMetaShare(scoped)
+            .withCodegen(codegen)
             .registerGuavaTypes(false)
             .withCompatibleMode(CompatibleMode.COMPATIBLE)
             .build();
     byte[] serialized = fury.serialize(resp);
     DemoResponse o = (DemoResponse) fury.deserialize(serialized);
     Assert.assertEquals(o.json, jsonObject);
+    Assert.assertEquals(o.objects, Collections.ofArrayList(jsonObject));
   }
 }
diff --git 
a/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java
 
b/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java
index cc825a69..df7d52e1 100644
--- 
a/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java
+++ 
b/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java
@@ -970,7 +970,7 @@ public abstract class BaseObjectCodecBuilder extends 
CodecBuilder {
             jitWriteMap(buffer, map, serializer, typeRef),
             new Invoke(serializer, "write", buffer, map));
     if (generateNewMethod) {
-      return invokeGenerated(ctx, ofHashSet(buffer, map), write, "writeMap", 
false);
+      return invokeGenerated(ctx, ofHashSet(buffer, map, serializer), write, 
"writeMap", false);
     }
     return write;
   }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@fury.apache.org
For additional commands, e-mail: commits-h...@fury.apache.org

Reply via email to