-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
dotnet/corefx
#41482Description
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:
namespace JsonProblem {
using System.Collections.Generic;
using System.Text.Json;
class ListString : List<string> {
}
class MyList<T> : List<T> {
}
class MyMyList<T> : MyList<T> {
}
class MyListString : MyList<string> {
}
class Program {
const string JSON = "[\"test\"]";
static void Main( string[] args ) {
JsonSerializer.Deserialize( JSON, typeof(string[]) ); // works
JsonSerializer.Deserialize( JSON, typeof(List<string>) ); // works
JsonSerializer.Deserialize( JSON, typeof(ListString) ); // also works
JsonSerializer.Deserialize( JSON, typeof(MyList<string>) ); // works
JsonSerializer.Deserialize( JSON, typeof(MyMyList<string>) ); // doesn't work
JsonSerializer.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.