Skip to content
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

feat(java): support Ignore inconsistent types deserialize #1737

Merged
merged 28 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
502e00a
add IgnoreTypeInconsistentSerializer
Weijiangd Jul 18, 2024
b56868d
Merge branch 'apache:main' into main
weijiang157152688 Jul 18, 2024
e3840d2
Merge branch 'apache:main' into main
weijiang157152688 Jul 18, 2024
41b6ac2
fix code style
Weijiangd Jul 18, 2024
2cb6ae4
Merge branch 'main' of github.com:157152688/incubator-fury into main
Weijiangd Jul 18, 2024
0b7b1b9
Merge branch 'main' of github.com:157152688/incubator-fury into main
Weijiangd Jul 18, 2024
f992e29
Merge branch 'main' of github.com:157152688/incubator-fury into main
Weijiangd Jul 18, 2024
e8c6dd9
Merge branch 'main' of github.com:157152688/incubator-fury into main
Weijiangd Jul 18, 2024
79cf39f
Merge branch 'main' of github.com:157152688/incubator-fury into main
Weijiangd Jul 18, 2024
e80ba01
Merge branch 'main' of github.com:157152688/incubator-fury into main
Weijiangd Jul 18, 2024
e1bffff
Merge branch 'main' of github.com:157152688/incubator-fury into main
Weijiangd Jul 18, 2024
9f50d1c
Merge branch 'apache:main' into main
weijiang157152688 Jul 19, 2024
a05760b
fix
Weijiangd Jul 19, 2024
1e2f686
fix code style
Weijiangd Jul 19, 2024
6a16362
fix code style
Weijiangd Jul 19, 2024
ae8e57d
Update java/fury-core/src/main/java/org/apache/fury/meta/ClassDef.java
chaokunyang Jul 19, 2024
9773d76
Merge remote-tracking branch 'upstream/main' into main
Weijiangd Jul 21, 2024
e92f1a7
fix
Weijiangd Jul 21, 2024
bef3307
fix
Weijiangd Jul 21, 2024
e711fd2
Merge branch 'apache:main' into main
weijiang157152688 Jul 23, 2024
9c84718
fix
Weijiangd Jul 24, 2024
5358657
Merge branch 'apache:main' into main
weijiang157152688 Jul 24, 2024
43dc955
fix
Weijiangd Jul 24, 2024
2ec3195
Merge branch 'main' of github.com:157152688/incubator-fury into main
Weijiangd Jul 24, 2024
4e4666e
fix code style
Weijiangd Jul 24, 2024
a2a1751
Merge branch 'apache:main' into main
weijiang157152688 Jul 24, 2024
9d6f232
fix code style
Weijiangd Jul 24, 2024
29208b1
Merge branch 'main' of github.com:157152688/incubator-fury into main
Weijiangd Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions java/fury-core/src/main/java/org/apache/fury/meta/ClassDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,18 @@ public List<Descriptor> getDescriptors(ClassResolver resolver, Class<?> cls) {
Descriptor descriptor =
descriptorsMap.get(fieldInfo.getDefinedClass() + "." + fieldInfo.getFieldName());
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);
} else {
if (descriptor == null) {
descriptors.add(newDesc);
continue;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this line

}
// Make DescriptorGrouper have consistent order whether field exist or not
// type is inconsistent use serialize type, except enum
if (!newDesc.getRawType().isAssignableFrom(descriptor.getRawType())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!newDesc.getRawType().isAssignableFrom(descriptor.getRawType())
if (!descriptor.getRawType().isAssignableFrom(newDesc.getRawType())

&& !descriptor.getRawType().isEnum()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this check first

descriptor = newDesc;
}
descriptor = descriptor.copyWithTypeName(newDesc.getTypeName());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add else here

descriptors.add(descriptor);
}
}
return descriptors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
import java.util.regex.Pattern;
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.apache.fury.config.FuryBuilder;
import org.apache.fury.config.Language;
import org.testng.Assert;
Expand Down Expand Up @@ -160,4 +163,53 @@ public void testEmptyObject() {
Fury fury = Fury.builder().requireClassRegistration(true).build();
assertSame(serDe(fury, new Object()).getClass(), Object.class);
}

@Test
public void testIgnoreTypeInconsistentSerializer()
Copy link
Collaborator

@chaokunyang chaokunyang Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this to MetaSharedObjectSerializerTest

throws InstantiationException, IllegalAccessException {
String codeA =
"public class TestA {"
+ " private int a = 1;"
+ " private Long b = 2L;"
+ " private String c = \"test\";"
+ " private int d;"
+ " private org.apache.fury.serializer.IgnoreTypeInconsistentSerializerTest.EnumFoo fo = org.apache.fury.serializer.IgnoreTypeInconsistentSerializerTest.EnumFoo.B;"
+ "}";

String codeB =
"public class TestA {"
+ " private Integer a ;"
+ " private int b = 30;"
+ " private String c = \"test\";"
+ " private String d;"
+ " private org.apache.fury.serializer.IgnoreTypeInconsistentSerializerTest.EnumFoo2 fo;"
+ "}";

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)));
}
}
Loading