4.7. Object Graphs
Serialization is recursive. When you serialize an object, all of its serializable fields are also serialized. Primitives are serialized by the DataOutput methods of the stream, and objects are serialized by writeObject. This fact is implicit in the Person example of this chapter, since lastName and firstName are themselves object types, not primitives. Recursion to referenced objects is highly desirable because it simplifies serializing complex graphs of objects all in one step. However, the fact that writeObject actually serializes an entire graph of objects introduces a few wrinkles that you need to be aware of.
The first issue is the danger of serializing far more data than you wanted. Consider a data object that lives inside ...
Get Component Development for the Java™ Platform now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.