Prerequisite: Run {@code TestForyXlangInterop#test_python_to_java_serialize} in Python + * first. It serializes a {@code DemoRequest(name="hello from python")} with xlang mode and + * writes the bytes to {@code src/test/resources/xlang/fory_xlang_from_python.bin} in this + * Java project. Commit that file so it is available on the classpath at test time. + */ + @Test + public void testXlangReadFromPython() throws IOException { + final String classpathResource = "/xlang/fory_xlang_from_python.bin"; + Fory xlangFory = buildXlangFory(); + + try (java.io.InputStream pythonBytesStream = + ForySerializerTest.class.getResourceAsStream(classpathResource)) { + Assert.assertNotNull( + "Classpath resource not found: " + classpathResource + + ". Run TestForyXlangInterop#test_python_to_java_serialize in Python first," + + " then commit the file to src/test/resources/xlang/.", + pythonBytesStream); + + // Java 8 compatible: read all bytes from InputStream manually. + java.io.ByteArrayOutputStream byteBuffer = new java.io.ByteArrayOutputStream(); + byte[] chunk = new byte[4096]; + int bytesRead; + while ((bytesRead = pythonBytesStream.read(chunk)) != -1) { + byteBuffer.write(chunk, 0, bytesRead); + } + byte[] pythonBytes = byteBuffer.toByteArray(); + + Assert.assertTrue("Expected non-empty bytes from Python", pythonBytes.length > 0); + MemoryBuffer readBuffer = MemoryBuffer.fromByteArray(pythonBytes); + DemoRequest fromPython = (DemoRequest) xlangFory.deserialize(readBuffer); + Assert.assertEquals("hello from python", fromPython.getName()); + } + } + + /** + * Cross-language test: Java reads the pre-generated bytes produced by the Python test + * ({@code TestForyXlangInterop#test_python_to_java_serialize}) and deserializes them. + * + *
The bin file {@code src/test/resources/xlang/fory_xlang_from_java.bin} is committed to
+ * this project and loaded from the classpath, so no external dependency is needed.
+ * Expected deserialized value: {@code DemoRequest(name="hello from java")}.
+ */
+ @Test
+ public void testXlangReadFromJava() throws IOException {
+ final String classpathResource = "/xlang/fory_xlang_from_java.bin";
+ Fory xlangFory = buildXlangFory();
+
+ try (java.io.InputStream javaBytesStream =
+ ForySerializerTest.class.getResourceAsStream(classpathResource)) {
+ Assert.assertNotNull("Classpath resource not found: " + classpathResource, javaBytesStream);
+
+ java.io.ByteArrayOutputStream buffer = new java.io.ByteArrayOutputStream();
+ byte[] chunk = new byte[1024];
+ int bytesRead;
+ while ((bytesRead = javaBytesStream.read(chunk)) != -1) {
+ buffer.write(chunk, 0, bytesRead);
+ }
+ byte[] javaBytes = buffer.toByteArray();
+
+ Assert.assertTrue("Expected non-empty bytes from Java", javaBytes.length > 0);
+ MemoryBuffer memoryBuffer = MemoryBuffer.fromByteArray(javaBytes);
+ DemoRequest fromJava = (DemoRequest) xlangFory.deserialize(memoryBuffer);
+ Assert.assertEquals("hello from java", fromJava.getName());
+ }
+ }
+}
diff --git a/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/blacklist/BlackListClass.java b/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/blacklist/BlackListClass.java
new file mode 100644
index 000000000..a4a1380b7
--- /dev/null
+++ b/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/blacklist/BlackListClass.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.alipay.sofa.rpc.codec.fory.model.blacklist;
+
+import java.io.Serializable;
+
+public class BlackListClass implements Serializable {
+
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/none/NoneClassHasBlackClass.java b/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/none/NoneClassHasBlackClass.java
new file mode 100644
index 000000000..ee0085935
--- /dev/null
+++ b/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/none/NoneClassHasBlackClass.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.alipay.sofa.rpc.codec.fory.model.none;
+
+import com.alipay.sofa.rpc.codec.fory.model.blacklist.BlackListClass;
+
+import java.io.Serializable;
+
+public class NoneClassHasBlackClass implements Serializable {
+
+ private BlackListClass blackListClass;
+
+ public BlackListClass getBlackListClass() {
+ return blackListClass;
+ }
+
+ public void setBlackListClass(BlackListClass blackListClass) {
+ this.blackListClass = blackListClass;
+ }
+}
diff --git a/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/whitelist/DemoRequest.java b/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/whitelist/DemoRequest.java
new file mode 100644
index 000000000..caab488f6
--- /dev/null
+++ b/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/whitelist/DemoRequest.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.alipay.sofa.rpc.codec.fory.model.whitelist;
+
+import java.io.Serializable;
+
+public class DemoRequest implements Serializable {
+
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/whitelist/DemoResponse.java b/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/whitelist/DemoResponse.java
new file mode 100644
index 000000000..70759bcd6
--- /dev/null
+++ b/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/whitelist/DemoResponse.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.alipay.sofa.rpc.codec.fory.model.whitelist;
+
+import java.io.Serializable;
+
+public class DemoResponse implements Serializable {
+
+ private String word;
+
+ public String getWord() {
+ return word;
+ }
+
+ public void setWord(String word) {
+ this.word = word;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ DemoResponse that = (DemoResponse) obj;
+ return word != null ? word.equals(that.word) : that.word == null;
+ }
+
+ @Override
+ public int hashCode() {
+ return word != null ? word.hashCode() : 0;
+ }
+}
diff --git a/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/whitelist/DemoService.java b/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/whitelist/DemoService.java
new file mode 100644
index 000000000..1bdf480b5
--- /dev/null
+++ b/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/whitelist/DemoService.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.alipay.sofa.rpc.codec.fory.model.whitelist;
+
+public interface DemoService {
+
+ String say(DemoRequest request);
+
+ void sayVoid(DemoRequest request);
+
+ DemoResponse sayResponse(DemoRequest request);
+}
diff --git a/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/whitelist/WhiteClassHasBlackClass.java b/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/whitelist/WhiteClassHasBlackClass.java
new file mode 100644
index 000000000..796d22af6
--- /dev/null
+++ b/codec/codec-sofa-fory/src/test/java/com/alipay/sofa/rpc/codec/fory/model/whitelist/WhiteClassHasBlackClass.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.alipay.sofa.rpc.codec.fory.model.whitelist;
+
+import com.alipay.sofa.rpc.codec.fory.model.blacklist.BlackListClass;
+
+import java.io.Serializable;
+
+public class WhiteClassHasBlackClass implements Serializable {
+
+ private BlackListClass blackListClass;
+
+ public BlackListClass getBlackListClass() {
+ return blackListClass;
+ }
+
+ public void setBlackListClass(BlackListClass blackListClass) {
+ this.blackListClass = blackListClass;
+ }
+}
diff --git a/codec/codec-sofa-fory/src/test/resources/sofa-rpc/serialize_blacklist.txt b/codec/codec-sofa-fory/src/test/resources/sofa-rpc/serialize_blacklist.txt
new file mode 100644
index 000000000..464b64878
--- /dev/null
+++ b/codec/codec-sofa-fory/src/test/resources/sofa-rpc/serialize_blacklist.txt
@@ -0,0 +1 @@
+com.alipay.sofa.rpc.codec.fory.model.blacklist.
diff --git a/codec/codec-sofa-fory/src/test/resources/sofa-rpc/serialize_whitelist.txt b/codec/codec-sofa-fory/src/test/resources/sofa-rpc/serialize_whitelist.txt
new file mode 100644
index 000000000..6525a81fd
--- /dev/null
+++ b/codec/codec-sofa-fory/src/test/resources/sofa-rpc/serialize_whitelist.txt
@@ -0,0 +1,2 @@
+com.alipay.sofa.rpc.core.
+com.alipay.sofa.rpc.codec.fory.model.whitelist.
diff --git a/codec/codec-sofa-fory/src/test/resources/xlang/fory_xlang_from_java.bin b/codec/codec-sofa-fory/src/test/resources/xlang/fory_xlang_from_java.bin
new file mode 100644
index 000000000..50d00754d
Binary files /dev/null and b/codec/codec-sofa-fory/src/test/resources/xlang/fory_xlang_from_java.bin differ
diff --git a/codec/codec-sofa-fory/src/test/resources/xlang/fory_xlang_from_python.bin b/codec/codec-sofa-fory/src/test/resources/xlang/fory_xlang_from_python.bin
new file mode 100644
index 000000000..29539f8b4
Binary files /dev/null and b/codec/codec-sofa-fory/src/test/resources/xlang/fory_xlang_from_python.bin differ
diff --git a/codec/pom.xml b/codec/pom.xml
index 25814b811..98b576575 100644
--- a/codec/pom.xml
+++ b/codec/pom.xml
@@ -21,6 +21,7 @@