The JsonIgnore
attribute can be used to ignore certain properties in serialization. I was wondering if it is possible to do the opposite of that? So a JsonSeria
An alternative to MemberSerialization.OptIn
is using DataContract
/DataMember
attributes:
[DataContract]
public class Computer
{
// included in JSON
[DataMember]
public string Name { get; set; }
[DataMember]
public decimal SalePrice { get; set; }
// ignored
public string Manufacture { get; set; }
public int StockCount { get; set; }
public decimal WholeSalePrice { get; set; }
public DateTime NextShipmentDate { get; set; }
}
Source: http://james.newtonking.com/archive/2009/10/23/efficient-json-with-json-net-reducing-serialized-json-size