-
Notifications
You must be signed in to change notification settings - Fork 258
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): add deserial object with feature deserializeNonexistentClassNotWriteFullClassInfo feature #1932
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
import org.apache.fury.collection.MapEntry; | ||
import org.apache.fury.collection.Tuple2; | ||
import org.apache.fury.collection.Tuple3; | ||
import org.apache.fury.config.Config; | ||
import org.apache.fury.memory.MemoryBuffer; | ||
import org.apache.fury.meta.ClassDef; | ||
import org.apache.fury.resolver.ClassInfo; | ||
|
@@ -193,6 +194,7 @@ public Object read(MemoryBuffer buffer) { | |
ClassFieldsInfo fieldsInfo = getClassFieldsInfo(classDef); | ||
ObjectSerializer.FinalTypeField[] finalFields = fieldsInfo.finalFields; | ||
boolean[] isFinal = fieldsInfo.isFinal; | ||
Config config = fury.getConfig(); | ||
for (int i = 0; i < finalFields.length; i++) { | ||
ObjectSerializer.FinalTypeField fieldInfo = finalFields[i]; | ||
Object fieldValue; | ||
|
@@ -208,23 +210,35 @@ public Object read(MemoryBuffer buffer) { | |
fury, refResolver, classResolver, fieldInfo, isFinal[i], buffer); | ||
} | ||
} | ||
entries.add(new MapEntry(fieldInfo.qualifiedFieldName, fieldValue)); | ||
entries.add(new MapEntry(getFileName(fieldInfo.qualifiedFieldName, config), fieldValue)); | ||
} | ||
for (ObjectSerializer.GenericTypeField fieldInfo : fieldsInfo.otherFields) { | ||
Object fieldValue = ObjectSerializer.readOtherFieldValue(fury, fieldInfo, buffer); | ||
entries.add(new MapEntry(fieldInfo.qualifiedFieldName, fieldValue)); | ||
entries.add(new MapEntry(getFileName(fieldInfo.qualifiedFieldName, config), fieldValue)); | ||
} | ||
Generics generics = fury.getGenerics(); | ||
for (ObjectSerializer.GenericTypeField fieldInfo : fieldsInfo.containerFields) { | ||
Object fieldValue = | ||
ObjectSerializer.readContainerFieldValue(fury, generics, fieldInfo, buffer); | ||
entries.add(new MapEntry(fieldInfo.qualifiedFieldName, fieldValue)); | ||
entries.add(new MapEntry(getFileName(fieldInfo.qualifiedFieldName, config), fieldValue)); | ||
} | ||
obj.setEntries(entries); | ||
return obj; | ||
} | ||
} | ||
|
||
public static String getFileName(String qualifiedFieldName, Config config) { | ||
if (config.deserializeNonexistentClassNotWriteFullClassInfo()) { | ||
int index = qualifiedFieldName.lastIndexOf("."); | ||
if (index < 0) { | ||
return qualifiedFieldName; | ||
} | ||
return qualifiedFieldName.substring(index + 1); | ||
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. This will create a new string everytime for deserialization, which is very slow. A better method is rename 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. And we should skip duplicated field name in super class if this option is enabled |
||
} else { | ||
return qualifiedFieldName; | ||
} | ||
} | ||
|
||
public static final class NonexistentEnumClassSerializer extends Serializer { | ||
private final NonexistentEnum[] enumConstants; | ||
private final MetaStringResolver metaStringResolver; | ||
|
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.
We'd better get the option here, and pass that flag to
getFileName
method