-
Notifications
You must be signed in to change notification settings - Fork 339
fix(java): Compatible mode on de/serialize api failed to deserialize #1996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
43110f3
fix(java):Compatible mode on de/serialize api failed to deserialize
orisgarno 1c7a45f
fix: header file
orisgarno ead89ec
fix: fix test not register classes when using COMPATIBLE mode
orisgarno 0423642
fix: revert accidental change
orisgarno 3a77a28
Update java_serialization_guide.md
orisgarno ff1ab72
Update java_serialization_guide.md
orisgarno f5cc361
Update java_serialization_guide.md
orisgarno bd0e757
fix: documentation
orisgarno 3e2325f
fix: documentation
orisgarno 1e28057
Update docs/guide/java_serialization_guide.md
orisgarno 8ed6e84
Update docs/guide/java_serialization_guide.md
orisgarno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...est/java/org/apache/fury/serializer/compatible/DifferentPOJOCompatibleSerializerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * 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.compatible; | ||
|
|
||
| import org.apache.fury.Fury; | ||
| import org.apache.fury.config.CompatibleMode; | ||
| import org.apache.fury.config.Language; | ||
| import org.apache.fury.serializer.compatible.classes.ClassCompleteField; | ||
| import org.apache.fury.serializer.compatible.classes.ClassMissingField; | ||
| import org.testng.Assert; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| /** | ||
| * Test COMPATIBILITY mode that supports - same field type and name can be deserialized to other | ||
| * class with different name - scrambled field order to make sure it could handle different field | ||
| * order - missing or extra field from source class to target class - generic class | ||
| */ | ||
| public class DifferentPOJOCompatibleSerializerTest extends Assert { | ||
|
|
||
| Fury getFury(Class<?>... classes) { | ||
| Fury instance = | ||
| Fury.builder() | ||
| .withLanguage(Language.JAVA) | ||
| .withRefTracking(true) | ||
| .withCompatibleMode(CompatibleMode.COMPATIBLE) | ||
| .withMetaShare(true) | ||
| .withScopedMetaShare(true) | ||
| .requireClassRegistration(false) | ||
| .withAsyncCompilation(true) | ||
| .serializeEnumByName(true) | ||
| .build(); | ||
| if (classes != null) { | ||
| for (Class<?> clazz : classes) { | ||
| instance.register(clazz); | ||
| } | ||
| } | ||
| ; | ||
| return instance; | ||
| } | ||
|
|
||
| @Test | ||
| void testTargetHasLessFieldComparedToSourceClass() throws InterruptedException { | ||
|
|
||
| ClassCompleteField<String> subclass = new ClassCompleteField<>("subclass", "subclass2"); | ||
| ClassCompleteField<ClassCompleteField<String>> classCompleteField = | ||
| new ClassCompleteField<>(subclass, subclass); | ||
| byte[] serialized = getFury(ClassCompleteField.class).serializeJavaObject(classCompleteField); | ||
| ClassMissingField<ClassMissingField<String>> classMissingField = | ||
| getFury(ClassMissingField.class).deserializeJavaObject(serialized, ClassMissingField.class); | ||
|
|
||
| assertEq(classCompleteField, classMissingField); | ||
| } | ||
|
|
||
| @Test | ||
| void testTargetHasMoreFieldComparedToSourceClass() throws InterruptedException { | ||
|
|
||
| ClassMissingField<String> subclass = new ClassMissingField<>("subclass"); | ||
| ClassMissingField classMissingField = new ClassMissingField(subclass); | ||
| byte[] serialized = getFury(ClassMissingField.class).serializeJavaObject(classMissingField); | ||
|
|
||
| ClassCompleteField classCompleteField = | ||
| getFury(ClassCompleteField.class) | ||
| .deserializeJavaObject(serialized, ClassCompleteField.class); | ||
|
|
||
| assertEq(classCompleteField, classMissingField); | ||
| } | ||
|
|
||
| void assertEq(ClassCompleteField classCompleteField, ClassMissingField classMissingField) { | ||
| assertEqSubClass( | ||
| (ClassCompleteField) classCompleteField.getPrivateFieldSubClass(), | ||
| (ClassMissingField) classMissingField.getPrivateFieldSubClass()); | ||
| assertEquals(classCompleteField.getPrivateMap(), classMissingField.getPrivateMap()); | ||
| assertEquals(classCompleteField.getPrivateList(), classMissingField.getPrivateList()); | ||
| assertEquals(classCompleteField.getPrivateString(), classMissingField.getPrivateString()); | ||
| assertEquals(classCompleteField.getPrivateInt(), classMissingField.getPrivateInt()); | ||
| } | ||
|
|
||
| void assertEqSubClass( | ||
| ClassCompleteField classCompleteField, ClassMissingField classMissingField) { | ||
| assertEquals( | ||
| classCompleteField.getPrivateFieldSubClass(), classMissingField.getPrivateFieldSubClass()); | ||
| assertEquals(classCompleteField.getPrivateMap(), classMissingField.getPrivateMap()); | ||
| assertEquals(classCompleteField.getPrivateList(), classMissingField.getPrivateList()); | ||
| assertEquals(classCompleteField.getPrivateString(), classMissingField.getPrivateString()); | ||
| assertEquals(classCompleteField.getPrivateInt(), classMissingField.getPrivateInt()); | ||
| } | ||
| } |
60 changes: 60 additions & 0 deletions
60
...-core/src/test/java/org/apache/fury/serializer/compatible/classes/ClassCompleteField.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * 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.compatible.classes; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
|
|
||
| @EqualsAndHashCode | ||
| @Getter | ||
| public class ClassCompleteField<T> { | ||
| private boolean privateBoolean = true; | ||
| private int privateInt = 10; | ||
| private String privateString = "notNull"; | ||
| private Map<String, String> privateMap; | ||
| private List<String> privateList; | ||
| private T privateFieldSubClass; | ||
|
|
||
| private boolean privateBoolean2 = true; | ||
| private int privateInt2 = 10; | ||
| private String privateString2 = "notNull"; | ||
| private Map<String, String> privateMap2; | ||
| private List<String> privateList2; | ||
| private T privateFieldSubClass2; | ||
|
|
||
| public ClassCompleteField(T privateFieldSubClass, T privateFieldSubClass2) { | ||
| privateMap = new HashMap<>(); | ||
| privateMap.put("a", "b"); | ||
| privateList = new ArrayList<>(); | ||
| privateList.add("a"); | ||
|
|
||
| privateMap2 = new HashMap<>(); | ||
| privateMap2.put("a", "b"); | ||
| privateList2 = new ArrayList<>(); | ||
| privateList2.add("a"); | ||
|
|
||
| this.privateFieldSubClass = privateFieldSubClass; | ||
| this.privateFieldSubClass2 = privateFieldSubClass2; | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
...y-core/src/test/java/org/apache/fury/serializer/compatible/classes/ClassMissingField.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * 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.compatible.classes; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
|
|
||
| @EqualsAndHashCode | ||
| @Getter | ||
| public class ClassMissingField<T> { | ||
| private T privateFieldSubClass; | ||
| private List<String> privateList; | ||
| private Map<String, String> privateMap; | ||
| private String privateString = "missing"; | ||
| private int privateInt = 999; | ||
| private boolean privateBoolean = false; | ||
|
|
||
| public ClassMissingField(T privateFieldSubClass) { | ||
| privateMap = new HashMap<>(); | ||
| privateMap.put("z", "x"); | ||
| privateList = new ArrayList<>(); | ||
| privateList.add("c"); | ||
| this.privateFieldSubClass = privateFieldSubClass; | ||
| } | ||
| } |
55 changes: 55 additions & 0 deletions
55
...re/src/test/java/org/apache/fury/serializer/compatible/classes/SubclassCompleteField.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * 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.compatible.classes; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @EqualsAndHashCode | ||
| public class SubclassCompleteField { | ||
| private boolean privateBoolean = true; | ||
| private int privateInt = 10; | ||
| private String privateString = "notNull"; | ||
| private Map<String, String> privateMap; | ||
| private List<String> privateList; | ||
|
|
||
| private boolean privateBoolean2 = true; | ||
| private int privateInt2 = 10; | ||
| private String privateString2 = "notNull"; | ||
| private Map<String, String> privateMap2; | ||
| private List<String> privateList2; | ||
|
|
||
| public SubclassCompleteField() { | ||
| privateMap = new HashMap<>(); | ||
| privateMap.put("a", "b"); | ||
| privateList = new ArrayList<>(); | ||
| privateList.add("a"); | ||
|
|
||
| privateMap2 = new HashMap<>(); | ||
| privateMap2.put("a", "b"); | ||
| privateList2 = new ArrayList<>(); | ||
| privateList2.add("a"); | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
...ore/src/test/java/org/apache/fury/serializer/compatible/classes/SubclassMissingField.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * 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.compatible.classes; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @EqualsAndHashCode | ||
| public class SubclassMissingField { | ||
| private boolean privateBoolean = true; | ||
| private int privateInt = 10; | ||
| private String privateString = "notNull"; | ||
| private Map<String, String> privateMap; | ||
| private List<String> privateList; | ||
|
|
||
| public SubclassMissingField() { | ||
| privateMap = new HashMap<>(); | ||
| privateMap.put("a", "b"); | ||
| privateList = new ArrayList<>(); | ||
| privateList.add("a"); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.