-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
System.Text.Json: Fix polymorphic state bug when using ReferenceHandler.IgnoreCycles #111808
System.Text.Json: Fix polymorphic state bug when using ReferenceHandler.IgnoreCycles #111808
Conversation
Clear the polymorphic state after ignoring a reference to prevent subsequent object writes from inheriting it.
|
||
worker1.Office.Staff = [worker1]; | ||
|
||
await Test_Serialize_And_SerializeAsync(worker1, """{"Office":{"Staff":[null],"Dummy":{}}}""", s_optionsIgnoreCycles); |
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.
This looks good. Could you also include a test for the same type using ReferenceHandler.Preserve
?
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.
IgnoreCycles and Preserve tests are a bit separated, so I just copied the classes over. I could otherwise just add another two lines in this test if youd like that better.
[experimenting with copilot reviews] |
@danmoseley Seems it never provided a review? |
Judging by the test failures this type |
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!
Thanks for your patience. Seems like the remaining test failures are unrelated. |
Thank you for your contribution @yesmey! |
Clear the polymorphic state after ignoring a reference in an array to prevent subsequent objects from inheriting it.
Add a test which triggered an assertion in
runtime/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverter.MetadataHandling.cs
Line 74 in 03b2d3d
and covers the scenario reported in #111790
Fixes #111790