XML serialization - when to use DataContractSerializer / Binary / XMLSerialiser

I looked at it for a while

Binary serialization seems to be discouraged, since any change to field names interrupts serialization =? Not good

XMLSerializer is problematic because you have to provide a constructor and public fields without arg, although you have more control over the elements that are attributes or elements, and their naming

DataContractSerializer is good, but all suclassses should be explicitly added, which is a shame

However, I came across a NetDataContractSerializer that does not have this limitation.

If your goal is C # serialization and there are no big restrictions on xml size, NetDataContractSerializer will always be here.

+5
source share
2 answers

Dan Rigsby has a really good comparative article on XmlSerializer and DataContractSerializer , and also touches on NetDataContractSerializer.

DataContractSerializer:

  • fast - about 10% faster than XmlSerializer
  • it is compatible - works flawlessly with Java, Ruby - you name it
  • uses the explicit opt-in model - you need to note what is serialized
  • no constructor required
  • can serialize non-public elements and internal fields
  • does not support attributes on XML nodes

DCS , , , .

XmlSerializer

  • , , ( )
  • - Java, Ruby -

XmlSerializer , , - .

NetDataContractSerializer - - , , .NET - .NET ( ). WCF " ".

- . - , - . "" , - , ...

+10
, DataContractSerializer, XmlSerializer .NET , protobuf-net ( .NET, ).
+2

All Articles