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 15 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
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,16 @@ public List<Descriptor> getDescriptors(ClassResolver resolver, Class<?> cls) {
Descriptor descriptor =
descriptorsMap.get(fieldInfo.getDefinedClass() + "." + fieldInfo.getFieldName());
Descriptor newDesc = fieldInfo.toDescriptor(resolver);
if (descriptor != null) {
if (descriptor == null
|| !descriptor.getRawType().isEnum()
&& !newDesc.getRawType().isAssignableFrom(descriptor.getRawType())) {
chaokunyang marked this conversation as resolved.
Show resolved Hide resolved
// Make DescriptorGrouper have consistent order whether field exist or not
// type is inconsistent use serialize type, except enum
descriptors.add(newDesc);
} else {
// Make DescriptorGrouper have consistent order whether field exist or not
descriptor = descriptor.copyWithTypeName(newDesc.getTypeName());
descriptors.add(descriptor);
} else {
descriptors.add(newDesc);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)));
}
}
Loading