I have a complex object, with fields and reference to database that I would like to pass as serialized object. I implemented the interface, but on the other hand it doesn’t work out, and get unexpected errors.
What I would like to do, is before serialization to tell that only the ID is serialized, and after on deserialization to get back the ID and reconstruct the item more easily.
In order to help for a code, I have
setId();
getId();
and Load() methods
I would like to be done inside by Object.
How can this be done?
It is meaningless to serialize a database resourse so you will want to set your non serializable fields as
transientand then resolve them in thereadObjectmethod. e.g.:Here the id field will be deserialized in the defaultReadObject(), but if you want a database resource you will have to manage that yourself as transient data such as this cannot be transferred between JVMs.