How can I serialize a class that is not marked serializable
I am using class A from my co-worker and is not marked serializable. I tried to serialize it and got an error.
I tried to get class B from class A and designated class B as serializable. However, the compiler still complains that A is not serializable. Is there any work other than asking my colleague to change the code to mark it as serializable?
+3
source to share
2 answers
You can only serialize the derived class, check the following post:
Serializing / Deserializing Derived Class
However, in this case, you will end up serializing all the public and protected elements of the base class, there is no way to avoid this until you specify an explicit base class class and attribute, like [XmlIgnore]
0
source to share