How can I serialize an object that does not implement Serializable? I cannot mark it Serializable because the class is from a 3rd party library.
How can I serialize an object that does not implement Serializable? I cannot mark
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t serialise a class that doesn’t implement
Serializable, but you can wrap it in a class that does. To do this, you should implementreadObjectandwriteObjecton your wrapper class so you can serialise its objects in a custom way.transient.writeObject, first calldefaultWriteObjecton the stream to store all the non-transient fields, then call other methods to serialise the individual properties of your non-serialisable object.readObject, first calldefaultReadObjecton the stream to read back all the non-transient fields, then call other methods (corresponding to the ones you added towriteObject) to deserialise your non-serialisable object.I hope this makes sense. 🙂