Andre Pena
Andre Pena

Reputation: 59336

For serialization in .NET, should I use JavaScriptSerializer and XmlSerializer or their DataContract counterparts?

For serialization on .NET, should I use JavaScriptSerializer and XmlSerializer or their DataContract counterparts (DataContractXmlSerializer and DataContractJsonSerializer)?

EDIT

I want to serialize things to store on files, or to send through the internet. I need some flexibility as to how the output will look like sometimes.

Upvotes: 3

Views: 597

Answers (2)

Cos Callis
Cos Callis

Reputation: 5084

My default choice would be to use JSON, there would need to be a compelling reason to go beyond that. What are your endpoints? Communication channel? Package size?

If this is this for an ASP.NET application, then JSON is likely your best choice. The standard I am using for best is:

  • robust serialization capabilities readily built into or available to .NET applications

  • lightest package load

    and

  • easy to understand what is going on

Upvotes: 1

Teoman Soygul
Teoman Soygul

Reputation: 25732

If you are using WCF, use DataContract* serializers. Otherwise XmlSerializer is pretty much the .NET standard for generating readable serialization file. JavaScriptSerializer/Json.NET are also very good alternatives for web stuff (i.e. for consuming web services, or posting simple REST queries, etc.).

Upvotes: 3

Related Questions