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 fails on deserializing into sub-subclasses of system collections #31009
When trying to deserialize into a class that has a class being a valid deserialization target for a collection higher in the class inheritance graph than its direct parent, the deserialization fails.
Example code:
namespaceJsonProblem{usingSystem.Collections.Generic;usingSystem.Text.Json;classListString:List<string>{}classMyList<T>:List<T>{}classMyMyList<T>:MyList<T>{}classMyListString:MyList<string>{}classProgram{conststringJSON="[\"test\"]";staticvoidMain(string[]args){JsonSerializer.Deserialize(JSON,typeof(string[]));// worksJsonSerializer.Deserialize(JSON,typeof(List<string>));// worksJsonSerializer.Deserialize(JSON,typeof(ListString));// also worksJsonSerializer.Deserialize(JSON,typeof(MyList<string>));// worksJsonSerializer.Deserialize(JSON,typeof(MyMyList<string>));// doesn't workJsonSerializer.Deserialize(JSON,typeof(MyListString));// doesn't work}}}
All the above classes worked OK in Json.NET - IMVHO, the deserializer should handle them, which it doesn't.
Activity
steveharter commentedon Sep 30, 2019
cc @layomia it appears that deserialization only works for one additional level of inheritance with generics.
ahsonkhan commentedon Oct 21, 2019
Re-opening until fixed for 3.1
ahsonkhan commentedon Oct 24, 2019
This issue has been fixed in release/3.1 (dotnet/corefx#41523).
@FyiurAmron, can you please use the 3.1-preview1 (or master) build and verify the issue has been fixed?
https://www.nuget.org/packages/System.Text.Json/4.7.0-preview1.19504.10
You can reference the latest master System.Text.Json NuGet package from https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json
FyiurAmron commentedon Oct 27, 2019
@ahsonkhan @layomia verified fixed & working OK in https://www.nuget.org/packages/System.Text.Json/4.7.0-preview1.19504.10
ericstj commentedon Oct 29, 2019
Closing as fix is in 3.1, some tests are remaining to be merged once branch opens but we can let the PR track those.