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

Fix unsupported type detection when serializing polymorphic System.Type instances #67618

Merged

Conversation

eiriktsarpalis
Copy link
Member

Fix #67588.

@ghost
Copy link

ghost commented Apr 5, 2022

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

Fix #67588.

Author: eiriktsarpalis
Assignees: -
Labels:

area-System.Text.Json

Milestone: -

@eiriktsarpalis eiriktsarpalis requested a review from krwq April 5, 2022 20:26
@eiriktsarpalis eiriktsarpalis added this to the 7.0.0 milestone Apr 5, 2022
@@ -72,6 +72,7 @@ async Task RunTest<T>(string json)
[Fact]
public async Task SerializeUnsupportedType()
{
// TODO refactor to Xunit theory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be done as part of this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a pervasive pattern so I'd rather it be done in a separate PR.

Copy link
Member

@krwq krwq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with suggestion

@@ -124,6 +124,20 @@ async Task RunTest<T>(T value)
serialized = await Serializer.SerializeWrapper(obj, new JsonSerializerOptions { IgnoreNullValues = true });
Assert.Equal(@"{}", serialized);
}

#if !BUILDING_SOURCE_GENERATOR_TESTS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this being run in source-gen mode?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Polymorphic scenaria will throw InvalidOperationException before we get the chance to exercise the changed codepath.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. FWIW when there are consequential divergences in source-gen/reflection behavior, we add a separate test variant for source-gen, e.g. here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I'm familiar with that pattern but FWIW it seems to encourage repetition of test definitions (or even divergence because only one implementation gets updated like in this case). Going forward I'd prefer it if we could avoid overriding test methods and either use compile conditionals or runtime parameterization (e.g. if (this.SerializerWrapper.IsSourceGenerated) ...)

@eiriktsarpalis
Copy link
Member Author

Test failures unrelated to Json

@eiriktsarpalis eiriktsarpalis merged commit 0aa1248 into dotnet:main Apr 12, 2022
@eiriktsarpalis eiriktsarpalis deleted the fix-unsupported-type-polymorphism branch April 12, 2022 16:07
@ghost ghost locked as resolved and limited conversation to collaborators May 12, 2022
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.

System.Text.Json.JsonSerializer does not work with Dictionary<string, object>
4 participants