I would like to serialize and deserialize objects without having to worry about the entire class graph.
Flexibility is key. I would like to be able to serialize any object passed to me without complete attributes needed throughout the entire object graph.
That means that Binary Serialization is not an option as it only works with the other .NET Platforms. I would also like something readable by a person, and thus decipherable by a management program and other interpreters.
I’ve found problems using the DataContract, JSON, and XML Serializers.
- Most of these errors seem to center around Serialization of Lists/Dictionaries (i.e. XML Serializable Generic Dictionary).
- ‘Add any types not known statically to the list of known types – for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.’
Please base your answers on actual experiences and not theory or reading of an article.
Have you considered serializing to JSON instead of XML?
Json.NET has a really powerful and flexible serializer that has no problems with Hashtables/generic dictionaries and doesn’t require any particular attributes. I know because I wrote it 🙂
It gives you heaps of control through various options on the serializer and it allows you to override how a type is serialized by creating a JsonConverter for it.
In my opinion JSON is more human readable than XML and Json.NET gives the option to write nicely formatted JSON.
Finally the project is open source so you can step into the code and make modifications if you need to.