I used to have simple classes like below:
public class Product {
public Money Price {get; set;}
}
public class Money {
public decimal Amount {get; set;}
public CurrencyEnum Currency {get;set;}
}
I stored serialized entities in the XML format in database. The stored XML looked more or less like below:
<Product>
<Price>
<Amount>1000</Amount>
<Currency>USD</Currency>
</Price>
</Product>
As my needs for displaying the currency changed, I switched to using NodaMoney library, and simply changed the type for the property (my mistake) in Product class. NodaMoney's type has a different structure when serialized:
<Product>
<Price Currency="USD">100</Price>
</Product>
Which made it a breaking change and I get errors during deserialization. I'm using XmlSerializer and I need both old and new format of the Price field to deserialize properly into the new NodaMoney's type. Moreover there might be Currency node missing in some legacy entries, which I need to populate with some default value. What would be the best approach to do this?