Well, of course, there is an obvious decision to put Serializable on it. I understand that this is not always an option.
Perhaps you can extend Address and put Serializable on the child you created. Then make Employee have a Child field instead of an Address field.
Here are a few more things to keep in mind:
- You can save the
Employee.address field as the Address type. You can serialize if you call Employee.setAddress(new SerializableAddress()) - If
Address is null, you can serialize the entire employee, even if the Address type is not serializable. - If you mark
Address as transient, it will skip trying to serialize Address . This may solve your problem.
Then there are other “serializations,” such as XStream , which do not require the marker interface to work. It depends on your requirements, be it an option.
source share