I have a simple object that I'm roundtripping through JSON. It serializes just fine, but I deserialize it one of the values is set to the default value (0, in this particular case). Why is that?
Here's my object:
public class CurrencyExchangeRate
{
public string CurrencyCode { get; private set; }
public decimal Rate { get; private set; }
public CurrencyExchangeRate(string currencyCode, decimal exchangeRate)
{
this.CurrencyCode = currencyCode;
this.Rate = exchangeRate;
}
}
This serializes to JSON as something like {"CurrencyCode":"USD", "Rate": 1.10231}. But when I deserialize it the Rate field is always set to 0. The CurrencyCode field is correctly set, so clearly deserialization is not failing entirely, just the one field is failing.