Description
I've recently handled serialising and deserialising polymorphic lists with system.text.json, and described an issue I had to workaround here: #56297
This above issue covers a case where I want to use SJT
to directly serialise / deserialise an instance of my class with a polymorphic list which is good.
However suppose I wanted to use my class with a polymorphic list, with the IOptions
pattern. In this case system.text.json converter is now redundant, as ConfigurationBuilder.AddJson
essentially reads the json into key value pairs in the IConfiguration - it doesn't deserialise the json into instances of concrete types. This is ofcourse how its meant to work, but it does then mean that if I want an instance of an options class containing a polymorphic list (where each item in the list has some type descriminator specified as a config value) I need a way to take control of how the object instance is materialised from the IConfiguration values. For example, when my options instance is created, I want to be able to have some logic inspect the key value pairs in IConfiguration for it's polymorphic list property, and then for each item, check its discriminator value, and then new() up (or bind) the appropriate derived type to add to the polymorphic list. Is there something on the roadmap that would enable me to do this?