如何在 class 路径上没有实现 class 的情况下反序列化 "Serialization" 的实例?

how to deserialize an instance of "Serialization" without the implementation class on the classpath?

我正在编写一个需要从字节数组中获取 java.io.Serializable 实例的工具。
困难在于 "real" class 不在(也不可能...)在 class 路径上(我不会在这里解释为什么...)。
下面的代码在 is.readObject() 上以 ClassNotFoundException 失败,因为实现 class 不在 class 路径
上 问:
有可能实现这一目标吗?通过反思?通过使用 Unsafe?通过使用 ClassLoader 的子 class?或者...?

byte[] data = ...
try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data));) {
   Object o = ois.readObject();
   Serializable s = (Serializable)o;
}

Is iis possible to achieve this?

没有

by reflection?

没有

by using Unsafe?

没有

by using a sub class of ClassLoader?

是的,但是 class 加载程序仍然需要从某个地方获取 class。 RMI 代码库功能就是一个很好的例子。