Serialization and Deserialization

Serialization is a process of converting an object into a stream of data, to easily transfer over the network or to save to disk.   So, using this concept of serialization, we can serialize any object to XML string.
Here is a person class that we can serialize.


Here is the code that takes the person object into string of xml format.

Using Serialization in .NET is provided by the System.Runtim.Serialization name space.

Once you have the XML string, now you can save it to disk, store it into database, or transfer over the network.
Here is the deserialization method that takes serialized string of XML into the person object.

Kyoungsu Do
Software Quality Engineer
ImageSource, Inc. 

 

The DataContractSerializer – XML Files Made Easy

With the release of .NET 3.5, Microsoft has included a fun new tool for data serializing.  The DataContractSerializer was introduced as a replacement for the current XmlSerializer class, and is the preferred XML data serializer of developers at ImageSource.

The DataContractSerializer class uses opt-in properties for it’s serialization rather than the XmlSerializer class’s opt-out methodology.  This means that the programmer must specify what class properties are to included in serialization.  It’s also up to the programmer to serialize fields, properties and non-public data.

Continue reading