You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[System.Text.Json] JsonExtensionData should allow non-JsonElement types during serialization #29774
This serializes correctly. If I annotate the Extensions property with JsonExtensionDataAttribute, serialization fails with:
The data extension property 'WebApplication1.Test2Controller+TestModel.Extensions' cannot contain dictionary values of type 'System.Int32'. Dictionary values must be of type JsonElement.
It's not entirely clear why serialization requires the type be an instance of JsonElement. Additionally, it's not particularly trivial to produce JsonElement instances to put inside a dictionary.
Could this constraint be removed so that it's treated the same as a regular dictionary for the purposes of serialization?
Activity
pranavkm commentedon Jun 5, 2019
Note that in the one use case that MVC uses this feature, it stores arbitrary content (strings or numbers) in the
JsonExtensionDatabacked dictionary.pranavkm commentedon Jun 5, 2019
cc @steveharter
MarcoRossignoli commentedon Jun 5, 2019
Guys I'm working on this if you can take a look at dotnet/corefx#38262 and let me know what you think I could bring it to the end.
steveharter commentedon Jun 5, 2019
The request is only for polymorphic serialize, which for round-tripping on subsequent deserialize will create JsonElement.
This means on deserialize the values should always be JsonElement, and we shouldn't try to convert to int, string, etc.
cc @MarcoRossignoli