0

My first question is that should I serialize each individual object in the arrayList or should I serialize the whole arrayList because I know that ArrayLists are serializable.

Also, how would I send it from a server to a client. I'm thinking of using ObjectOutputStream on the server side. But I think my instructor wants each and every object to be serialized.

How would I serialize each object and then add it to the ArrayList. After adding it to the ArrayList, I'd need to send the ArrayList to client which after receiving it, will de-serialize each object and read it.

4

2 回答 2

0

No matter how you achieve serializing the items, you'll also need to serialize whatever you send them in. I see no real difference between serializing a list of serializables vs. doing so individually. Then you'd still have to serialize the list itself.

If you are not required to use ObjectInputStream, just to serialize and send, consider using XML. You have a couple options - XMLEncoder/XMLDecoder (older) or JAXB (newer), for example. One advantage with XML serialization over ObjectInput/OutputStream is the data is textual and (relatively) human readable on-the-wire.

于 2013-04-24T01:20:51.560 回答
0

我将如何序列化每个对象,然后将其添加到 ArrayList。

你不会的。您只需将其添加到ArrayList并序列化即可。

将其添加到 ArrayList 后,我​​需要将 ArrayList 发送到客户端,客户端在接收到它后,将对每个对象进行反序列化并读取它。

不,客户端将反序列化ArrayList. 完毕。

于 2013-04-24T01:29:04.210 回答