Architecture – Pros and cons of intrusive and non-intrusive serialization

Architectureserialization

I am interesting in the pros and cons of serialization: intrusive and non-intrusive.

On the one hand it seems non-intrusive is easy to use – class to be serialized should not be updated. It seems convenient for simple cases. E.g. XStream.Net implements such approach.

But the issues can appear if this class is connected in some way with other classes, e.g. stores indices of global objects which should be serialized as well. In this case non-intrusive approach looks dangerous.

Concerning intrusive implementation. It is good that developer can directly specify what and how to serialize (of course if serialization technology is flexible enough).
E.g. Microsoft .Net has intrusive approach implemented for XML serialization – attributes should be specified for classes and members.

Other ideas?

Best Answer

From C++ perspective there is a very informative article, which every developer needs to read at once. It basically lays down the difference in serialization for approached intrusive and non-intrusive.

A practical guide to C++ serialization is another well written source to be aware of. More info from Boost C++ libraries on Serializable Concept.