简体   繁体   English

复杂对象序列化

[英]Complex object serialization

I've got a few questions on the topic of serializing complex objects and writing them to a file. 关于序列化复杂对象并将其写入文件,我有几个问题。

First, I've got a few objects which are connected to each other, in more precise ways I have an object which holds another objects in a list which are also holding another object. 首先,我有一些相互连接的对象,以更精确的方式,我有一个对象在列表中包含另一个对象,这些对象也包含另一个对象。 so, the overall architecture of the object I want to write to the file looks as follows: 因此,我要写入文件的对象的整体体系结构如下所示:

ComplexObject
-> holds List of NotSoComplexObject(s)
--> every NotSoComplexObject
---> holds a SimpleObject

all of the objects implement the Serializable interface. 所有对象都实现Serializable接口。

if I try to serialize the ComplexObject and write it to a file I got no specific Exception as the Exception.getMessage() method returns NULL (so, it's an Exception that is being thrown, but it's not clear which Exception it is). 如果我尝试序列化ComplexObject并将其写入文件,则没有特定的Exception,因为Exception.getMessage()方法返回NULL(因此,这是抛出的Exception,但不清楚是哪个Exception)。

Is there a way to achieve the ComplexObject to be serialized and stored in a file? 有没有一种方法可以将ComplexObject序列化并存储在文件中?

The exception itself tells you what type it is. 异常本身会告诉您它是什么类型。 I assume its NotSerializableException. 我假设其为NotSerializableException。

In Java you might do... 在Java中,您可以...

System.err.println(e);
e.printStackTrace();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM