I have a model that i retrieve as json and as xml.
I want to seralize different properties for Json that for xml.
[Serlializable]
class Model
{
public bool? IncludeAlways {get;set;}
[XmlIgnore]
public bool? IncludeForJson {get;set;}
[JsonIgnore]
public bool? IncludeForXml {get;set;}
}
Sample use:
new Model()
{
IncludeAlways = true,
IncludeForJson = true,
IncludeForXml = true
};
It results the expected Xml:
<Model>
<IncludeAlways>true</IncludeAlways>
<IncludeForXml>true</IncludeForXml>
</Model>
but not the expected json
I expected some json is like this:
{ "IncludeAlways":true, "IncludeForJson":true }
but i have the "IgnoreForXml" property is
{ "IncludeAlways":true }
Using .Net Framework 2.0 Newtonsoft JSON.Net for json and .Net Framework 2.0 standard XmlSerializer for xml. The xml is generated as a result of a WebMethod and i asume that is serialized with the standard XmlSerializer that serialize to xml.