chaokunyang commented on code in PR #2312:
URL: https://github.com/apache/fory/pull/2312#discussion_r2173208061
##########
java/fory-core/src/main/java/org/apache/fory/resolver/XtypeResolver.java:
##########
@@ -232,16 +228,126 @@ private void register(
if (type.isEnum()) {
classInfo.serializer = new EnumSerializer(fory, (Class<Enum>) type);
} else {
- classInfo.serializer =
- new LazySerializer.LazyObjectSerializer(
- fory, type, () -> new ObjectSerializer<>(fory, type));
+ boolean codegen =
+ supportCodegenForJavaSerialization(type) &&
fory.getConfig().isCodeGenEnabled();
+ Class<? extends Serializer> objectSerializerClass =
+ getObjectSerializerClass(
+ type,
+ shareMeta,
+ codegen,
+ new JITContext.SerializerJITCallback<Class<? extends
Serializer>>() {
+ @Override
+ public void onSuccess(Class<? extends Serializer> result) {
+ setSerializer(
+ type,
+ Serializers.newSerializer(fory, type, result),
+ namespace,
+ typeName,
+ xtypeId);
+ if (classInfoCache.classInfo.cls == type) {
+ classInfoCache.classInfo = NIL_CLASS_INFO; // clear
class info cache
+ }
+ Preconditions.checkState(getSerializer(type).getClass() ==
result);
+ }
+
+ @Override
+ public Object id() {
+ return type;
+ }
+ });
+ classInfo.serializer = Serializers.newSerializer(fory, type,
objectSerializerClass);
}
}
classInfoMap.put(type, classInfo);
registeredTypeIds.add(xtypeId);
xtypeIdToClassMap.put(xtypeId, classInfo);
}
+ /**
+ * Set the serializer for <code>cls</code>, overwrite serializer if exists.
Note if class info is
+ * already related with a class, this method should try to reuse that class
info, otherwise jit
+ * callback to update serializer won't take effect in some cases since it
can't change that
+ * classinfo.
+ */
+ public <T> void setSerializer(
+ Class<T> cls, Serializer<T> serializer, String namespace, String
typeName, int xtypeId) {
+ addSerializer(cls, serializer, namespace, typeName, xtypeId);
+ }
+
+ /** Ass serializer for specified class. */
Review Comment:
what does `ass` means here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]