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?
2 Answers
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.
Comments
No. You have to add the serialization interface to those objects to. Otherwise you will not be able to serialize the ArrayList.
2 Comments
The Militant Hobo
I ask this question implying that the ArrayList objects implement serializable.
Damian Leszczyński - Vash
This is not obvious, but if it so then ArrayList should be serialized with success.