Newtonsoft JsonConverter to replicate the serialization of the JsonObjectAttribute on an IEnumerable
Can someone help me create a Newtonsoft.Json.JsonConverter that will write an IEnumerable the same way one is written if the class has the JsonObjectAttribute?
For example, given this class:
I need the result from this:
To look like this:
Doing the above works fine if the class has the JsonObjectAttribute on it like this:
However without the JsonOjectAttribute the result will look like this:
But I cannot use the attribute since I do not own the class I am trying to serialize in this way, Thus I need to write a converter to do this same thing but I am struggling to figure out how.
I tried googling this but I could not find any similar examples and everyone just seems to suggest using the JsonObject attribute, which I can't and do not want to use.
Any assistance would be appreciated.
2 Replies
Additionally I wish I could use System.Text.Json but it doesn’t seem like it will work either until this issue is resolved: https://github.com/dotnet/runtime/issues/63791
GitHub
Developers should have access to System.Text.Json's default interna...
Background and Motivation Currently, the default json converters used for objects and collection types are internal to System.Text.Json. The library uses hardcoded conventions to decide what defaul...
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.