R Pidugu

What happens if your serializable class contains a member which is not serializable in Java?

It is simple, the class will not be serializable, unless the field is declared transient (which will prevent the field from being serialized, i.e. it will not be saved).

It'll throw a NotSerializableException when you try to serialize it. To avoid that, make that field a "transient" field.

 private transient YourNonSerializableObject dontSerializeMe; // This won't be serialized

Subscribe to this Blog via Email :