-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Support deserialization for Struct properties that implements IList<T> #41223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add a new field into IListOfTConverter class to store the values to prevent unboxing when the TCollection is ValueType.
|
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
...stem.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListOfTConverter.cs
Outdated
Show resolved
Hide resolved
...stem.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListOfTConverter.cs
Outdated
Show resolved
Hide resolved
…ion<T>, IList Use constraint type instead of TCollection to avoid unboxing when TCollection is ValueType.
…T>, IDictionary<TKey, TValue>, IDictionary Use constraint type to cast to avoid unboxing when the target type is ValueType
|
Hi @layomia @steveharter I have updated my PR to resolve your comments. Are there anything else I can do to get this PR approved ? |
layomia
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes.
We also need to update the Add methods of the following converter types and add corresponding tests:
ICollectionOfTConverterIDictionaryConverterIDictionaryOfTKeyTValueConverterIListConverterIListOfTConverterISetOfTConverter
...ystem.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ISetOfTConverter.cs
Outdated
Show resolved
Hide resolved
...braries/System.Text.Json/tests/Serialization/CollectionTests/CollectionTests.Generic.Read.cs
Show resolved
Hide resolved
Modify the 'Add' method to use actual type casting.
|
@layomia I have just updated my PR. BenchmarkDotNet=v0.12.1.1405-nightly, OS=Windows 10.0.18363.1082 (1909/November2019Update/19H2)
Intel Core i7-9700 CPU 3.00GHz, 1 CPU, 8 logical and 8 physical cores
.NET Core SDK=5.0.100-preview.7.20366.6
[Host] : .NET Core 5.0.0 (CoreCLR 5.0.20.36411, CoreFX 5.0.20.36411), X64 RyuJIT
Job-WVOCPJ : .NET Core 5.0 (CoreCLR 42.42.42.42424, CoreFX 42.42.42.42424), X64 RyuJIT
PowerPlanMode=00000000-0000-0000-0000-000000000000 Arguments=/p:DebugType=portable Toolchain=CoreRun
IterationTime=250.0000 ms MaxIterationCount=20 MinIterationCount=15
WarmupCount=1
ArrayList
BinaryData
Dictionary_string, string
HashSet_String
HashTable
ImmutableDictionary_String, String
ImmutableSortedDictionary_String, String
IndexViewModel
Int32
LargeStructWithProperties
Location
LoginViewModel
MyEventListerViewModel
SimpleStructWithProperties
|
layomia
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sharing the benchmarks. The change is close to ready, I just have a few comments on the tests.
.../System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListConverter.cs
Show resolved
Hide resolved
...ies/System.Text.Json/tests/Serialization/TestClasses/TestClasses.GenericCollectionsStruct.cs
Outdated
Show resolved
Hide resolved
...braries/System.Text.Json/tests/Serialization/CollectionTests/CollectionTests.Generic.Read.cs
Show resolved
Hide resolved
...libraries/System.Text.Json/tests/Serialization/CollectionTests/CollectionTests.Dictionary.cs
Show resolved
Hide resolved
| } | ||
|
|
||
| { | ||
| GenericStructIDictionaryWrapper<string, string>? obj = JsonSerializer.Deserialize<GenericStructIDictionaryWrapper<string, string>?>("null"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when serializing a default instance of GenericStructIDictionaryWrapper<string, string>? Test this for GenericStructIListWrapper<int> as well.
- Serializing a default instance. - Deserializing a null json string.
|
@layomia Thanks for your comments. I've updated my PR, can you check if it is satisfied ? |
layomia
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Fixes #1998
Add a new field into IListOfTConverter class to store the values to prevent unboxing when the TCollection is ValueType.