Skip to content
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

Merged
merged 3 commits into from
Jul 15, 2021

Conversation

layomia
Copy link
Contributor

@layomia layomia commented Jul 13, 2021

Fixes #53393. The collection trimming tests are not updated in this PR (#53437).

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

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.

@ghost
Copy link

ghost commented Jul 13, 2021

Tagging subscribers to this area: @eiriktsarpalis, @layomia
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #53393. The collection trimming tests are not updated in this PR (#53437).

Author: layomia
Assignees: layomia
Labels:

area-System.Text.Json

Milestone: 6.0.0

@layomia layomia force-pushed the SrcGenCollections branch 5 times, most recently from 17ef405 to f78d7b9 Compare July 14, 2021 16:28
@layomia layomia marked this pull request as ready for review July 14, 2021 16:30
Copy link
Member

@steveharter steveharter left a 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.

@layomia layomia force-pushed the SrcGenCollections branch 3 times, most recently from 6ce1542 to 6c05c74 Compare July 15, 2021 02:47
@layomia layomia closed this Jul 15, 2021
@layomia layomia reopened this Jul 15, 2021
@layomia layomia closed this Jul 15, 2021
@layomia layomia reopened this Jul 15, 2021
@layomia
Copy link
Contributor Author

layomia commented Jul 15, 2021

FYI @eerhardt


if (converter.RequiresDynamicMemberAccessors)
{
converter.Initialize(Options, this);
Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

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 });
Copy link
Member

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
Copy link
Member

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;
Copy link
Member

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.

@layomia
Copy link
Contributor Author

layomia commented Jul 15, 2021

Test failures are unrelated. Will address further feedback in a follow-up.

@layomia layomia merged commit 0a5cf4e into dotnet:main Jul 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support more collections in JSON source generator
4 participants