为什么同一类的序列化对象在两个不同的项目中不同



所以我有两个项目。其中一个是servlet,另一个是JFrame。我试图在servlet中读取序列化的对象,但我得到了ClassNotFoundException。只有当我把所有类都放在我的servlet项目中编译它们时,它才开始工作。这是它应该的工作方式吗?serialization是否取决于编译的项目?(当然,如果类相同)

例如,我的班级的UPD定义图在servletJFrame类中。

来自 javadocs

When an object is serialized, information that identifies its class is recorded in
the serialized stream. However, the class's definition ("class file") itself is
not recorded. It is the responsibility of the system that is deserializing the
object to determine how to locate and load the necessary class files.

序列化将需要.class文件从序列化流创建对象。由于序列化对象不包含类定义,因此如果没有.class文件,则无法从流中提取对象。

最新更新