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 1a5c3578 feat(java): support Ignore inconsistent types deserialize
(#1737)
1a5c3578 is described below
commit 1a5c35788fdfcffbb518b44c77eb6c7cf7a3533d
Author: wei <[email protected]>
AuthorDate: Wed Jul 24 13:26:31 2024 +0800
feat(java): support Ignore inconsistent types deserialize (#1737)
## What does this PR do?
<!-- Describe the purpose of this PR. -->
## Related issues
<!--
Is there any related issue? Please attach here.
- #xxxx0
- #xxxx1
- #xxxx2
-->
## 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.
-->
- [x] Does this PR introduce any public API change?
- [x] 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.
-->
---------
Co-authored-by: weijiang.wj <[email protected]>
Co-authored-by: Shawn Yang <[email protected]>
---
.../main/java/org/apache/fury/meta/ClassDef.java | 13 +++-
.../serializer/MetaSharedObjectSerializerTest.java | 77 ++++++++++++++++++++++
2 files changed, 88 insertions(+), 2 deletions(-)
diff --git a/java/fury-core/src/main/java/org/apache/fury/meta/ClassDef.java
b/java/fury-core/src/main/java/org/apache/fury/meta/ClassDef.java
index cd10f1d1..35fb467d 100644
--- a/java/fury-core/src/main/java/org/apache/fury/meta/ClassDef.java
+++ b/java/fury-core/src/main/java/org/apache/fury/meta/ClassDef.java
@@ -237,8 +237,17 @@ public class ClassDef implements Serializable {
Descriptor newDesc = fieldInfo.toDescriptor(resolver);
if (descriptor != null) {
// Make DescriptorGrouper have consistent order whether field exist
or not
- descriptor = descriptor.copyWithTypeName(newDesc.getTypeName());
- descriptors.add(descriptor);
+ // fury builtin types skip
+ Class<?> rawType = newDesc.getRawType();
+ if (rawType.isEnum()
+ || rawType.isAssignableFrom(descriptor.getRawType())
+ || NonexistentClass.isNonexistent(rawType)
+ || rawType.isAssignableFrom(FinalObjectTypeStub.class)) {
+ descriptor = descriptor.copyWithTypeName(newDesc.getTypeName());
+ descriptors.add(descriptor);
+ } else {
+ descriptors.add(newDesc);
+ }
} else {
descriptors.add(newDesc);
}
diff --git
a/java/fury-core/src/test/java/org/apache/fury/serializer/MetaSharedObjectSerializerTest.java
b/java/fury-core/src/test/java/org/apache/fury/serializer/MetaSharedObjectSerializerTest.java
new file mode 100644
index 00000000..d102c2cd
--- /dev/null
+++
b/java/fury-core/src/test/java/org/apache/fury/serializer/MetaSharedObjectSerializerTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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 org.apache.fury.serializer;
+
+import org.apache.fury.Fury;
+import org.apache.fury.FuryTestBase;
+import org.apache.fury.ThreadSafeFury;
+import org.apache.fury.codegen.JaninoUtils;
+import org.apache.fury.config.CompatibleMode;
+import org.testng.annotations.Test;
+
+public class MetaSharedObjectSerializerTest extends FuryTestBase {
+
+ @Test
+ public void testIgnoreTypeInconsistentSerializer()
+ throws InstantiationException, IllegalAccessException {
+ String codeA =
+ "public class TestA {"
+ + " private int a = 1;"
+ + " private Long b = 2L;"
+ + " private String c = \"test\";"
+ + " private int d;"
+ + "}";
+
+ String codeB =
+ "public class TestA {"
+ + " private Integer a ;"
+ + " private int b = 30;"
+ + " private String c = \"test\";"
+ + " private String d;"
+ + "}";
+
+ Class<?> cls1 = JaninoUtils.compileClass(getClass().getClassLoader(), "",
"TestA", codeA);
+ Class<?> cls2 = JaninoUtils.compileClass(getClass().getClassLoader(), "",
"TestA", codeB);
+ ThreadSafeFury fury1 =
+ Fury.builder()
+ .withRefTracking(true)
+ .requireClassRegistration(false)
+ .withDeserializeNonexistentClass(true)
+ .withCompatibleMode(CompatibleMode.COMPATIBLE)
+ .deserializeNonexistentEnumValueAsNull(true)
+ .withScopedMetaShare(true)
+ .withCodegen(false)
+ .withClassLoader(cls1.getClassLoader())
+ .buildThreadSafeFury();
+ ThreadSafeFury fury2 =
+ Fury.builder()
+ .withRefTracking(true)
+ .requireClassRegistration(false)
+ .withDeserializeNonexistentClass(true)
+ .withCompatibleMode(CompatibleMode.COMPATIBLE)
+ .deserializeNonexistentEnumValueAsNull(true)
+ .withScopedMetaShare(true)
+ .withCodegen(false)
+ .withClassLoader(cls2.getClassLoader())
+ .buildThreadSafeFury();
+ Object data = cls1.newInstance();
+ System.out.println(fury2.deserialize(fury1.serialize(data)));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]