Tech News

What is Serialization??

Serialization is the process of converting an object into a stream of bytes in order to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.

The easiest way to make a class serializable is to mark it with the Serializable attribute as follows.

public class MyObject {
  public int n1 = 0;
  public int n2 = 0;
  public String str = null;
.NET offers 2 serializers: binary, SOAP, XML. The difference between binary and SOAP is:
binary is more efficient (time and memory used)
binary is not human-readable. SOAP isn't much better.
XML is slightly different:
it lives in System.Xml.Serialization
it uses [XmlIgnore] instead of [NonSerialized] and ignores [Serializable]
it doesn't serialize private class members
It is important to note that the Serializable attribute cannot be inherited.
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x