Assume I create a class Foo, whose instance variables are instances of different class's. Eg:
class Foo implements Serializable {
BarA barA;
BarB barB;
.
.
BarZ barZ;
}
I understand that when I serialize, I need to all the Bar's to be serializable, else I need to mark them as transient. But How to know which one's should be marked as transient ? Is this trail and error ?
You should make sure that all fields that decide the state of your
Foo
object are serializable, the rest can be transient.Noone can answer which fields belong to which category but you, the developer.