Difference between XMLSerializer and the DataContractserializer.

Posted By : Bipul Kumar Tiwari,

DataContractSerializer:

Opt-In Approach:

In this approach we need to specify each member, which we want to serialize. For example we want to serialize the firstname and lastname, not an designation member then we need to set the DataMember attribute to the firstname and lastname.

namespace Employee
{
[ServiceContract]
public interface IService1
{

}
[DataContract]
public class Emp
{
[DataMember()]
public string FirstName;

[DataMember()]
public string LastName;

public string Designation;

}
}

we are not applying the DataMember attribute to the designation member. That's why this member is not serialized.

XMLSerializer :

Opt-Out Approach

In this approach, members are assumed to be serialized except we mention it as NonSerialized.

namespace Employee
{
[ServiceContract]
public interface IService1
{

}
[Serializable()]
public class Emp
{

public string FirstName;
public string LastName;

[NonSerialized()]
public string Designation;

}
}

All Emp class members are going to be serialized but suppose we do not want to serialize the designation member then set the NonSerialized attribute on designation member.

Related Articles

 

About the Author

author
Its me BIPUL who is logically minded creative at heart , a good communicator , a self taught full stack developer. I constantly focuses on my thinking , reading , collecting and creating my work in a order to enhance my skills.

I discover new dimensions for growing bussiness with a proven record in creating database and programming. I have a strong technical skills as well as strong interpersonal skills. Read more...
 

Browse By Category

Popular Articles