-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Support more collections in STJ source generator #55566
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: @eiriktsarpalis, @layomia |
17ef405
to
f78d7b9
Compare
f78d7b9
to
ab75b8d
Compare
src/libraries/System.Text.Json/tests/Common/CollectionTests/CollectionTests.Specialized.Read.cs
Show resolved
Hide resolved
...tem.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/Serialization/CollectionTests.cs
Outdated
Show resolved
Hide resolved
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.
Misc feedback provided (none that can't be addressed after this PR)
Looks good pending green CI.
This new collection support is important to get in for Preview 7.
6ce1542
to
6c05c74
Compare
6c05c74
to
011c403
Compare
d408b89
to
01ffde9
Compare
FYI @eerhardt |
|
||
if (converter.RequiresDynamicMemberAccessors) | ||
{ | ||
converter.Initialize(Options, this); |
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.
does this account for the possibility that one converter instance is initialized by multiple JsonTypeInfo
instances? I think that it's occassionally possible although not sure it applies to converters that override RequiresDynamicMemberAccessors
.
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.
Hmm I think it could happen occasionally due to threading, but I think even in that case each JsonTypeInfo
construction would create a separate converter instance, and the first one to complete would win, discarding the duplicates. Each converter instance would only be for a specific type, so there are no issues of creating invalid dynamic accessors.
{ | ||
JsonSerializerOptions options = new JsonSerializerOptions | ||
{ | ||
DefaultBufferSize = bufferSize | ||
}; | ||
|
||
string expectedJson = JsonSerializer.Serialize(source); | ||
string expectedJson = await JsonSerializerWrapperForString.SerializeWrapper(source); |
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.
Since this method call is only used to generate the expected JSON string, we don't really need to exercise any async APIs here.
{ | ||
JsonSerializerOptions options = new JsonSerializerOptions | ||
{ | ||
DefaultBufferSize = bufferSize | ||
}; | ||
|
||
string expectedJson = JsonSerializer.Serialize(new { Data = source }); | ||
string expectedJson = await JsonSerializerWrapperForString.SerializeWrapper(new { Data = source }); |
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.
Ditto for this and all the other expectedJson
values in this file.
@@ -9,24 +9,25 @@ | |||
using System.Threading.Tasks; | |||
using Xunit; | |||
|
|||
namespace System.Text.Json.Tests.Serialization | |||
namespace System.Text.Json.Serialization.Tests |
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 fixing this!
@@ -7,7 +7,7 @@ | |||
using System.Threading; | |||
using System.Threading.Tasks; | |||
using Xunit; | |||
using Utf8MemoryStream = System.Text.Json.Tests.Serialization.CollectionTests.Utf8MemoryStream; |
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.
FWIW the System.Text.Json.Tests.Serialization
namespace has crept up in quite a few other places as well.
Test failures are unrelated. Will address further feedback in a follow-up. |
Fixes #53393. The collection trimming tests are not updated in this PR (#53437).