diff --git a/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/util/SerializeUtils.java b/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/util/SerializeUtils.java index 482a38138..1eaf9e63a 100644 --- a/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/util/SerializeUtils.java +++ b/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/util/SerializeUtils.java @@ -23,6 +23,10 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; /** * @author: yuanyuan @@ -30,7 +34,17 @@ */ public class SerializeUtils { - public static Object serializeTransform(Object source, ClassLoader targetClassLoader) { + private static Object _serializeTransform(Object source, ClassLoader targetClassLoader) { + try { + if (null == source + || source.getClass().getClassLoader() == targetClassLoader + || targetClassLoader.loadClass(source.getClass().getName()).getClassLoader() == source + .getClass().getClassLoader()) { + return source; + } + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } Object target; ClassLoader currentContextClassloader = Thread.currentThread().getContextClassLoader(); try { @@ -56,4 +70,22 @@ public static Object serializeTransform(Object source, ClassLoader targetClassLo } return target; } + + public static Object serializeTransform(Object originalSource, ClassLoader targetClassLoader) { + if (originalSource.getClass().isArray()) { + Object[] sources = (Object[]) originalSource; + if (sources.length > 0) { + Object[] targets = (Object[]) Array.newInstance(sources.getClass() + .getComponentType(), sources.length); + for (int i = 0; i < sources.length; i++) { + targets[i] = _serializeTransform(sources[i], targetClassLoader); + } + return (Object) targets; + } else { + return originalSource; + } + } else { + return _serializeTransform(originalSource, targetClassLoader); + } + } }