Just like the title says, is there a way to check if an object is serializable, and if not, make it so at run time?
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.
Short answer – no.
Longer answer – yes, using byte-code manipulation, for example with asm. But you should really consider whether this is needed. Serialization is a serious matter (Effective Java has a whole chapter on serialization)
Btw, there are alternatives to binary serialization, that do not require the object implementing
Serializble(as pointed by Jacob in the comments):java.beans.XMLEncoder.encode(..)is the xml version ofObjectOutputStream