Reputation: 19
When an ArrayList in java is serialized, are the objects stored in it serialized with it? Or do I have to get and serialize all of it's contents?
Upvotes: 0
Views: 310
Reputation: 30865
No. You have to add the serialization interface to those objects to. Otherwise you will not be able to serialize the ArrayList.
Upvotes: 1
Reputation: 533442
When you serialise any object, it will generally serialise everything in it. Otherwise that object hasn't really been serialised.
As Vash points out, those objects have to implement Serializable
for this to work, or you get a NotSerializableException. Classes in the JDK already implement Serializable where it makes sense to do so.
Upvotes: 3