Is it possible to override the type resolution using JSON.NET based on a property of the JSON object? Based on existing APIs, it looks like I need a way of accepting a JsonPropertyCollection and returning the Type to be created.
NOTE: I’m aware of the TypeNameHandling attribute, but that adds a $type property. I do not have control over the source JSON.
It would appear that this is handled by creating a custom JsonConverter and adding it to
JsonSerializerSettings.Convertersbefore deserialisation.nonplus has left a handy sample on the JSON.NET discussions board on Codeplex. I’ve modified the sample to return custom
Typeand deferring to the default creation mechanism, rather than creating the object instance on the spot.And here is the example usage (also updated as mentioned above):