When using XSD.EXE to generate classes from an XML Schema, it generates xxxSpecified members of any primitives of a given object:
<xs:complexType name ="Foo">
<xs:all>
<xs:element name ="Count" type = "xs:integer"/>
</xs:all>
</xs:complexType>
....generates:
public class Foo
{
public int Count { get; set; }
public bool CountSpecified { get; set; }
}
It appears the latest version of JSON.NET can automatically set these properties when deserializing.
string request = "{ Count : 10 }";
var object = JsonConvert.Deserialize<Foo>(request)
Assert.IsTrue(object.Count = 10); // Yup
Assert.IsTrue(object.CountSpecified == true); //Also yup - JSON.NET works!
However, when going the other way, the xxxSpecified properties are included in the JSON output, which is incorrect, as it is not part of the schema.
string request = JsonConvert.Serialize(object);
//{
// Count: 10,
// CountSpecified : true <-- This is incorrect - should not be output
//}
Is there any setting I am missing that controls whether to output the xxxSpecified attributes? How can I suppress it?
(Note: This is a permutation of a question answered here:
JSON.NET, XmlSerializer and "Specified" property
...but it involves creating extension classes, which is not possible for me, as there are hundreds of classes in the schema and I can't change the inheritance hierarchy. So the answer won't work. Looking for another way.)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…