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

jark pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fluss.git


The following commit(s) were added to refs/heads/main by this push:
     new 13930df90 [common] Fix Serialize BinaryString throws 
NotSerializableException (#1496)
13930df90 is described below

commit 13930df90203a42723daa2c39a78e64cb0494b3c
Author: Jark Wu <[email protected]>
AuthorDate: Fri Aug 8 00:49:04 2025 +0800

    [common] Fix Serialize BinaryString throws NotSerializableException (#1496)
---
 .../java/com/alibaba/fluss/row/BinarySection.java  | 10 ++++++--
 .../com/alibaba/fluss/row/BinaryStringTest.java    | 28 ++++++++++++++++++++++
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git 
a/fluss-common/src/main/java/com/alibaba/fluss/row/BinarySection.java 
b/fluss-common/src/main/java/com/alibaba/fluss/row/BinarySection.java
index 9189f790a..f1937f5d2 100644
--- a/fluss-common/src/main/java/com/alibaba/fluss/row/BinarySection.java
+++ b/fluss-common/src/main/java/com/alibaba/fluss/row/BinarySection.java
@@ -87,15 +87,21 @@ abstract class BinarySection implements MemoryAwareGetters, 
Serializable {
         }
     }
 
+    /**
+     * Support Java Serialization by customize writeObject and readObject 
methods, because {@link
+     * MemorySegment} doesn't support Java Serialization.
+     */
     private void writeObject(ObjectOutputStream out) throws IOException {
-        out.defaultWriteObject();
         byte[] bytes = toBytes();
         out.writeInt(bytes.length);
         out.write(bytes);
     }
 
+    /**
+     * Support Java Serialization by customize writeObject and readObject 
methods, because {@link
+     * MemorySegment} doesn't support Java Serialization.
+     */
     private void readObject(ObjectInputStream in) throws IOException, 
ClassNotFoundException {
-        in.defaultReadObject();
         byte[] bytes = new byte[in.readInt()];
         IOUtils.readFully(in, bytes);
         pointTo(MemorySegment.wrap(bytes), 0, bytes.length);
diff --git 
a/fluss-common/src/test/java/com/alibaba/fluss/row/BinaryStringTest.java 
b/fluss-common/src/test/java/com/alibaba/fluss/row/BinaryStringTest.java
index 634d16c86..18e0661ba 100644
--- a/fluss-common/src/test/java/com/alibaba/fluss/row/BinaryStringTest.java
+++ b/fluss-common/src/test/java/com/alibaba/fluss/row/BinaryStringTest.java
@@ -24,6 +24,10 @@ import 
com.alibaba.fluss.testutils.junit.parameterized.Parameters;
 import org.junit.jupiter.api.TestTemplate;
 import org.junit.jupiter.api.extension.ExtendWith;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.math.BigDecimal;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
@@ -146,6 +150,30 @@ public class BinaryStringTest {
         assertThat(empty.getSizeInBytes()).isEqualTo(0);
     }
 
+    @TestTemplate
+    public void testJavaSerialization() throws Exception {
+        String str = "hello world";
+        BinaryString bs = fromString(str);
+        byte[] data;
+
+        // serialization: object -> bytes
+        try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
+                ObjectOutputStream oos = new ObjectOutputStream(bos)) {
+
+            oos.writeObject(bs);
+            data = bos.toByteArray();
+        }
+
+        // deserialization:bytes -> object
+        try (ByteArrayInputStream bis = new ByteArrayInputStream(data);
+                ObjectInputStream ois = new ObjectInputStream(bis)) {
+            BinaryString deserializedString = (BinaryString) ois.readObject();
+
+            assertThat(deserializedString).isEqualTo(bs);
+            assertThat(deserializedString.toString()).isEqualTo(str);
+        }
+    }
+
     @TestTemplate
     public void compareTo() {
         assertThat(fromString("   ").compareTo(blankString(3))).isEqualTo(0);

Reply via email to