JsonIgnoreAttribute

Dec 19, 2009 at 5:39 PM

Hi guys,

 

I'm using EntitySpaces as my ORM and it created classes with the [XmlIgnore] attribute for properties that shouldn't be serialized. This is an automatic process and I cannot change this attribute to [JsonIgnore]. Is it possible to configure Json.net to use [XmlIgnore] instead of [JsonIgnore] ?

 

Thank you all,

 

Eduardo Freitas

Dec 19, 2009 at 6:38 PM

Overriding this line inside the method CreateProperty from the DefaultContractResolver seems to do the trick:

 

bool hasIgnoreAttribute = (JsonTypeReflector.GetAttribute<JsonIgnoreAttribute>(member) != null);

 

to:

 

bool hasIgnoreAttribute = (JsonTypeReflector.GetAttribute<JsonIgnoreAttribute>(member) != null) ||
          (JsonTypeReflector.GetAttribute<System.Xml.Serialization.XmlIgnoreAttribute>(member) != null);

Is there a better way to do it ?