ObjectInputStream自定义类加载器反序列化问题:未调用resolveClass() [英] ObjectInputStream custom classloader deserialization issue: resolveClass() not called
问题描述
我有一个 ObjectInputStream
,并希望使用自定义的 ClassLoader
加载类。
因此将创建 ObjectInputStream
的子类,该子类将覆盖 resolveClass()
函数。 / p>
现在,我的问题是我想在执行期间更改 ClassLoader
。但是有时候当我在此流上执行 readObject()
时,似乎未执行 resolveClass()
。然后用错误的 ClassLoader
加载类。
任何想法为什么 resolveClass()
不执行,如何解决此问题?
resolveClass( )
将在流中每个类描述符调用一次。我不知道如果您为相同的完全限定的类名编写了多个描述符(可能未指定)会发生什么。正确的解决方案是使用多个流(可以相互嵌套)。
I have an ObjectInputStream
and want to load classes with a custom ClassLoader
.
Thus is created a subclass of ObjectInputStream
that overrides the resolveClass()
function.
Now my problem is that i want to change the ClassLoader
during execution. But sometimes resolveClass()
does not seem to be executed when I do readObject()
on this stream. Then the class is loaded with the wrong ClassLoader
.
Any idea why resolveClass()
is not executed and how to solve this issue?
resolveClass()
will be called once per class descriptor in the stream. I have no idea what would happen if you wrote multiple descriptors for the same full qualified class name - probably unspecified. The correct solution would be to use multiple streams (could be nested within one another).
这篇关于ObjectInputStream自定义类加载器反序列化问题:未调用resolveClass()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!