It happens more than you think. JSON.NET does not recursively deserialize things, so for example if you have a JObject
inside of a JObject
and you call ToObject<IDictionary<string, string>>
on it, only the outer one will be converted, but the inner one will remain a JObject
. I have written a converter to take care of this, but I’ve literally only done it in the last week so it hasn’t made its way into any release, or even the master branch yet (it is on a branch called “json-leak”). As you can imagine it is quite delicate, so I plan to go over it one more time before I merge it.
The dynamicness of the system is to blame. JSON .NET does not want to make any assumptions about what you want to do, and it will choose the most performant and/or literal scenario above all unless you instruct it otherwise. The code you showed here is basically exactly what Couchbase Lite has been doing internally to ensure .NET types where needed. I hope to have this cleaned up for the 1.2 release scheduled for the middle of next month (with a preview release scheduled for the end of this month).