JSON IList Covariance

An Unexpected Roadblock I ran into a an unexpected roadblock the other day when refactoring code that controls JSON de-serialization. It forced me to read up on the dreaded topic of covariance and contravariance in C#. During code review, I was asked to change the technique I used to specify how JSON should be de-serialized into a root type that includes properties typed as interfaces. The conundrum is what classes should be instantiated for these properties? I solved this problem using Json.NET JsonSerializerSettings.TypeNameHandling. This embeds type names into JSON text as properties named “$type”. When the JSON text is de-serialized, […]