My desktop application serializes objects using XmlSerializer
. I was suggested to leverage DataContractSerializer
instead.
Under which scenarios should I use DataContractSerializer
?
Many thanks
Comments.
1. The output XML file is stored locally. No other applications deserialize objects from that XML file.
2. My application runs with .NET Framework 3.5 SP1.
DataContractSerializer can able to serialize types that implements Idictionary whereas XML serializer not. DataContractSerializer serializes all members which are marked with [DataMember] attribute even if member is marked private. XML serializer serialize only public members.
XML serialization is the process of converting XML data from its representation in the XQuery and XPath data model, which is the hierarchical format it has in a Db2® database, to the serialized string format that it has in an application.
Dan Rigsby has the ultimate post on this - go read it!
XmlSerializer vs. DataContractSerializer (web archive)
He says all there is to say, and in a very convincing way.
In short:
XmlSerializer:
DataContractSerializer is:
[DataMember]
will be serialized[DataMember]
will be serialized - whether it's public
or private
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With