I need to create a custom JSON.NET converter for a legacy system that flags null decimal values with...
var nulldec = decimal.MinValue;
(This was created before nullable types were introduced, and to change how this works will be a ton of work.)
When these min-values are serialized to JSON they need to be serialized as an empty string. When they are deserialized, if the value is empty string, it needs to convert to decimal.MinValue
.
Here is what I have so far (yes, not much). I think this is a simple conversion, but I am not seeing any articles that point me to how to work this for my situation nor any documentation on how to create custom converters. Can someone help please?
public class DecimalJsonConverter : JsonConverter
{
public override object ReadJson(JsonReader reader, Type objectType,
object existingValue, JsonSerializer serializer)
{
}
public override void WriteJson(JsonWriter writer, object value,
JsonSerializer serializer)
{
}
public override bool CanConvert(Type objectType)
{
return typeof(System.Decimal).IsAssignableFrom(objectType);
}
}