With the following Test class
public class Test {
[DefaultValue("Black")]
public Color ForeColor = Color.Black;
}
And the following serialization code:
var test = new Test();
var json = JsonConvert.SerializeObject(test, Newtonsoft.Json.Formatting.None,
new JsonSerializerSettings {
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
});
I get
{"ForeColor":"Black"}
Is there a (simple) way to have a Color property not serialized if it's the same as a specified default value.