Difference between DataContractSerializer vs XmlSerializer

后端 未结 2 1157
抹茶落季
抹茶落季 2021-02-04 11:06

I was going through WCF Fundamentals, Can anybody tells that under which scenarios should we use DataContractSerializer and XmlSerializer?

相关标签:
2条回答
  • 2021-02-04 11:51
    1. DataContractSerializer is better performance over Xmlserializer. This is because DataContratSerializer explicitly shows the which fields or properties are serialized into XML.

    2. DataContractSerializer can able to serialize types that implements Idictionary whereas XML serializer not.

    3. DataContractSerializer serializes all members which are marked with [DataMember] attribute even if member is marked private. XML serializer serialize only public members.

    These are some important difference.

    0 讨论(0)
  • 2021-02-04 11:57

    DataContractSerializer

    • Is meant to be used for serialization/deserialization of class in WCF service to and from either JSON or XML.
    • serializes properties and fields.
    • Is faster than XmlSerializer
    • Doesn't control how xml is generated. Should not be used when full control on generated XML structure is required

    XMLSerializer

    • XmlSerializer is only for XML serialization
    • Supports full control over the XML structure
    • Serializes only public properties
    0 讨论(0)
提交回复
热议问题