I need a serialization library for .net with better features than the default xml serializer. The problem is that it is not polymorphic – say you have class B : A { }, and have serialized an type B, you should be able to call A myBaseType = Deserialize(xml) on it and be returned an instance of type B in the myBaseType variable.
I have an implementation at http://refactormycode.com/codes/710-polymorphic-xml-serializer with unit tests that the serialization library should be able to deal with. This implementation will not work if an object to be serialized has a child type which is also a polymorphic serialized type, so I need something better.
thanks!
If you can handle the additional verbosity going to a serializer which embeds the type information into the resulting stream is probably for the best.
.Net provides the SoapFormatter which is overly verbose and does things that you probably won’t need but when you deserialize the stream it will simply give you back the appropriate objects (no need to specify a type just cast the root object to the type you know it to be).
As a fringe benefit it will correctly handle cycles and shared references within the object graph.