chaokunyang commented on code in PR #2271:
URL: https://github.com/apache/fury/pull/2271#discussion_r2118615132


##########
java/fory-core/src/main/java/org/apache/fory/Fory.java:
##########
@@ -222,8 +226,40 @@ public void register(Class<?> cls, String namespace, 
String typeName) {
     }
   }
 
+  private void validateSerializer(
+      Class<?> type,
+      Object serializerOrClass,
+      Class<?> parentType,
+      Class<?> requiredSerializerBase) {
+    if (!parentType.isAssignableFrom(type)) {
+      return;
+    }
+    boolean valid = false;
+    if (serializerOrClass instanceof Class) {
+      valid = requiredSerializerBase.isAssignableFrom((Class<?>) 
serializerOrClass);
+    } else if (serializerOrClass instanceof Serializer) {
+      valid = requiredSerializerBase.isInstance(serializerOrClass);
+    }
+    if (!valid) {
+      throw new IllegalArgumentException(
+          "Serializer for type "
+              + type.getName()
+              + " must extend "
+              + requiredSerializerBase.getSimpleName()
+              + ", but got "
+              + serializerOrClass.getClass().getName());
+    }
+  }
+
+  private void validateCollectionSerializer(Class<?> type, Object 
serializerOrClass) {
+    validateSerializer(
+        type, serializerOrClass, Collection.class, 
AbstractCollectionSerializer.class);

Review Comment:
   type may not be subclass of Collection?



-- 
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]

Reply via email to