In the JsonConverter WriteJson custom method of JsonConverter WriteJson can I appeal the default serialization behavior of an object from JsonConverter ?
That is, can I postpone to serialization, which would have happened if the user converter had not been registered?
More details
Given the price class
public class Price { public string CurrencyCode; public decimal Amount; }
The normal behavior of Newtonsoft Json.NET is to serialize the Price instance as null only when the link is null. In addition, I would like to serialize Price instances as null at any time to Price.Amount equal to zero. Here is what I have worked so far ( full source )
public class PriceConverter : JsonConverter {
The last part of this implementation is fragile. If, for example, I added fields to Price , my serialization would be broken (and I donβt know how a good way to write a test that detects a gap).
My serializer has several types of behavior configured in a separate assembly through JsonSerializerSettings that I need to save (for example, object property names). I cannot add a direct relationship between the two. In fact, I use the [JsonConverter(typeof(PriceConverter))] attribute to indicate that my custom converter should be used for Price .
source share