Development With A Dot

Blog on development in general, and specifically on .NET

Sponsors

News

My Friends

My Links

Permanent Posts

Portuguese Communities

.NET Serializers

(UPDATED) 

As of version 3.5 SP1, .NET comes along with the following serializers:

  • System.Runtime.Serialization.Formatters.Binary.BinaryFormatter: binary serializer used in .NET Remoting, type information is included, understands System.Runtime.Serialization.ISerializable;
  • System.Runtime.Serialization.Formatters.Soap.SoapFormatter: SOAP (XML) serializer used in .NET Remoting, includes type information, understands System.Runtime.Serialization.ISerializable;
  • System.Runtime.Serialization.DataContractSerializer: XML serializer used in WCF, does not include type information;
  • System.Runtime.Serialization.Json.DataContractJsonSerializer: JSON serializer used in WCF, does not include type information;
  • System.Runtime.Serialization.NetDataContractSerializer: binary serializer used in WCF, includes type information;
  • System.Xml.Serialization.XmlSerializer: XML serializer used in ASP.NET Web Services (ASMX), type information is not included, understands System.Xml.Serialization.IXmlSerializable; 
  • System.Web.UI.LosFormatter: uses ObjectStateFormatter internally, does not account by itself;
  • System.Web.UI.ObjectStateFormatter: binary or text (base 64 encoded) serializer used in ASP.NET for storing items in view state, control state and session, type information is included, understands System.Runtime.Serialization.ISerializable.

There isn't, however, a common interface for all of these serializers, and, in fact, they have quite different requirements.

The base interfaces are:

  • System.Runtime.Serialization.IFormatter: for BinaryFormatter, SoapFormatter, NetDataContractSerializer and ObjectStateFormatter;
  • System.Runtime.Serialization.XmlObjectSerializer: for DataContractSerializer, DataContractJsonSerializer and NetDataContractSerializer;
  • XmlSerializer doesn't have any interface that specifies its behavior.

The interfaces that can be used to control the serialization process are:

  • System.Runtime.Serialization.ISerializable: for all the IFormatter serializers;
  • System.Xml.Serialization.IXmlSerializable: for XmlSerializer.

Also, there are a couple of attribute classes that can be used to control the serialization process:

  • System.Runtime.Serialization.OptionalFieldAttribute (IFormatter): field may be missing from the serialized content
  • System.Runtime.Serialization.NonSerializedAttribute (IFormatter): field is not serialized
  • System.Xml.Serialization.SoapAttributeAttribute (XmlSerializer)
  • System.Xml.Serialization.SoapElementAttribute (XmlSerializer)
  • System.Xml.Serialization.SoapEnumAttribute (XmlSerializer)
  • System.Xml.Serialization.SoapIgnoreAttribute (XmlSerializer)
  • System.Xml.Serialization.SoapIncludeAttribute (XmlSerializer)
  • System.Xml.Serialization.SoapTypeAttribute (XmlSerializer)
  • System.Xml.Serialization.SoapDocumentServiceAttribute (XmlSerializer): default format is Document
  • System.Xml.Serialization.SoapRpcServiceAttribute (XmlSerializer): default format is RPC
  • System.Xml.Serialization.SoapRpcMethodAttribute (XmlSerializer): method uses SOAP RPC format
  • System.Xml.Serialization.SoapDocumentMethodAttribute (XmlSerializer): method uses SOAP Document format
  • System.Xml.Serialization.XmlAnyAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlAnyElementAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlArrayAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlArrayItemAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlAttributeAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlChoiceIdentifierAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlElementAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlEnumAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlIgnoreAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlIncludeAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlRootAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlTextAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlTypeAttribute (XmlSerializer)
  • System.Xml.Serialization.XmlSchemaProviderAttribute (XmlSerializer): applied on a method that returns the XML schema
  • System.Runtime.Serialization.CollectionDataContractAttribute (XmlObjectSerializer)
  • System.Runtime.Serialization.DataContractAttribute (XmlObjectSerializer)
  • System.Runtime.Serialization.DataMemberAttribute (XmlObjectSerializer)
  • System.Runtime.Serialization.EnumMemberAttribute (XmlObjectSerializer)
  • System.Runtime.Serialization.IgnoreDataMemberAttribute (XmlObjectSerializer)
  • System.Runtime.Serialization.XmlSerializerFormatAttribute (XmlObjectSerializer): choose XmlSerializer instead of DataContractSerializer

Note that the Soap* attributes are only considered if the SoapBindingUse.Encoded is set for the Use property of the binding, in ASP.NET Web Services, otherwise, its the Xml* attributes.

It would be good to see a common interface (perhaps IFormatter, since it's the most common) for all of these serializers.

Bookmark and Share

Comments

No Comments