Monday, 19 August 2013

when we serialize serializable object using JSON.Net, JSON string is different from DatacontractJSON serializer

when we serialize serializable object using JSON.Net, JSON string is
different from DatacontractJSON serializer

I have a class some thing like below
[Serializable]
public class sample
{
private int m_width;
private int m_height;
public int Width
{
get
{
return this.m_width;
}
set
{
this.m_width = value;
}
}
public int Height
{
get
{
return this.m_height;
}
set
{
this.m_height = value;
}
}
}
If I use DataContractJsonSerializer to serialize the object of this class
i get the json string as below:
{"m_height":1345,"m_width":1234}
If I use Newtonsoft.Json.dll to serialize this I am getting the out put
like below:
{"Width":1234,"Height":1345}
Why DataContractSerializer using backing fields for serialization if class
marked as serializable ?
Is there any way I can achieve the same thing using Newtonsoft.Json.dll

No comments:

Post a Comment