-
Notifications
You must be signed in to change notification settings - Fork 262
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
Changes from 11 commits
502e00a
b56868d
e3840d2
41b6ac2
2cb6ae4
0b7b1b9
f992e29
e8c6dd9
79cf39f
e80ba01
e1bffff
9f50d1c
a05760b
1e2f686
6a16362
ae8e57d
9773d76
e92f1a7
bef3307
e711fd2
9c84718
5358657
43dc955
2ec3195
4e4666e
a2a1751
9d6f232
29208b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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; | ||||||
} | ||||||
// Make DescriptorGrouper have consistent order whether field exist or not | ||||||
// type is inconsistent use serialize type, except enum | ||||||
if (!newDesc.getRawType().isAssignableFrom(descriptor.getRawType()) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
&& !descriptor.getRawType().isEnum()) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this check first |
||||||
descriptor = newDesc; | ||||||
} | ||||||
descriptor = descriptor.copyWithTypeName(newDesc.getTypeName()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add |
||||||
descriptors.add(descriptor); | ||||||
} | ||||||
} | ||||||
return descriptors; | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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))); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete this line