-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Fix unsupported type detection when serializing polymorphic System.Type instances #67618
Conversation
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsFix #67588.
|
@@ -72,6 +72,7 @@ async Task RunTest<T>(string json) | |||
[Fact] | |||
public async Task SerializeUnsupportedType() | |||
{ | |||
// TODO refactor to Xunit theory |
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.
could this be done as part of this PR?
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.
It's a pervasive pattern so I'd rather it be done in a separate PR.
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 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 |
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.
Why isn't this being run in source-gen mode?
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.
Polymorphic scenaria will throw InvalidOperationException
before we get the chance to exercise the changed codepath.
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.
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.
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.
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) ...
)
Test failures unrelated to Json |
Fix #67588.