-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Add support for types derived from supported BCL collections #39001
Conversation
src/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.AddProperty.cs
Show resolved
Hide resolved
src/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.Helpers.cs
Show resolved
Hide resolved
At this point, is this required for 3.0? Is risk acceptable? |
Yes, it fixes some important issues raised by partners and community members, and it's pretty well tested. https://github.com/dotnet/corefx/issues/38767. |
Ok. |
cc @pranavkm |
...ystem.Text.Json/src/System/Text/Json/Serialization/Converters/DefaultIDictionaryConverter.cs
Show resolved
Hide resolved
src/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.Helpers.cs
Outdated
Show resolved
Hide resolved
src/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.Helpers.cs
Show resolved
Hide resolved
src/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.Helpers.cs
Show resolved
Hide resolved
src/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.Helpers.cs
Outdated
Show resolved
Hide resolved
src/System.Text.Json/tests/Serialization/TestClasses.NonGenericCollections.cs
Outdated
Show resolved
Hide resolved
This change makes it impossible to have a Specialized collections can be necessary if the json has multiple ways of declaring a list, e.g. {
"List1" :
{
"Count": 50,
"Values" : [ "test", ... ]
},
"List2" : [ "test", ... ]
} public class A
{
public MyCollection List1 { get; set; }
public List<string> List2 { get; set }
}
public class MyCollection : List<string> { }
public class MyConverterFactory : JsonConverterFactory
{
public override bool CanConvert( Type typeToConvert )
{
return ( typeToConvert == typeof( MyCollection ) );
}
public override JsonConverter CreateConverter( Type typeToConvert, JsonSerializerOptions options )
{
// return the converter
throw new NotImplementedException();
}
} From // Get implemented type, if applicable.
// Will return the propertyType itself if it's a non-enumerable, string, or natively supported collection.
Type implementedType = GetImplementedCollectionType(propertyType);
if (implementedType != propertyType)
{
jsonInfo = CreateProperty(implementedType, implementedType, implementedType, null, typeof(object), options);
}
else
{
jsonInfo = CreateProperty(propertyType, propertyType, propertyType, propertyInfo, classType, options);
}
A solution could be to provide I don't know if I should have opened a new issue for this, but now at least you know.. |
@phizch this PR is closed and won't be tracked; please open a new issue for this. It's okay to reference this PR in that, though. CC @ahsonkhan |
Yes, please. |
…corefx#39001) * Add support for types derived from supported BCL collections * Fix merge issues * Re-add commented-out tests * Address review comments Commit migrated from dotnet/corefx@6005a1e
Fixes https://github.com/dotnet/corefx/issues/38767.
Fixes https://github.com/dotnet/corefx/issues/38521.
Supported in this PR: user-defined types that implement natively supported collections that have "add" methods e.g.
IList<T>
,Queue<T>
,IDictionary
,IList
e tc.Not supported in this PR: user-defined types that implement natively supported collections that don't have "add" methods e.g.
IEnumerable<T>
,ICollection
,IReadOnyList<T>
and immutable collections.