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


Inheritance of this class a to B does not work.



You should avoid marking any class as serializable that is not a DTO (Data Transfer Object) or message class. In other cases, you can mark the class as serializable.

0


source


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







All Articles