This project has moved and is read-only. For the latest updates, please go here.

Ignore for serialization, but not for deserialization

Aug 16, 2013 at 6:06 PM
What is the best way to ignore a property for serialization, but not for deserialization? I think the way to do this is to add a method:

public int MyProperty {get;set;}
public bool ShouldSerializeMyProperty() { return false; }

This works fine, but it isn't great because the method has to be public and with a handful of properties adding methods becomes tedious. The JsonProperty class already has a ShouldSerialize property, but it isn't included in the JsonPropertyAttribute. It would be awesome if I could do:

public int MyProperty {get;set;}