-
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
Address edge scenarios with JsonSerializer's property visibility #37720
Conversation
@@ -261,8 +261,8 @@ public static void VeryLargeAmountOfEnumsToSerialize() | |||
// Use multiple threads to perhaps go over the soft limit of 64, but not by more than a couple. | |||
Parallel.For(0, 8, i => JsonSerializer.Serialize((MyEnum)(46 + i), options)); | |||
|
|||
// Write the remaining enum values. We should not store any more values in | |||
// the cache. If we do, we may throw OutOfMemoryException on some machines. | |||
// Write the remaining enum values. The cache is capped to avoid |
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.
Following up on #37710 (comment).
Are the current semantics in this PR consistent with Newtonsoft? |
d5b6fa0
to
b121ea8
Compare
b121ea8
to
766572f
Compare
With the latest commit, we are largely aligned with Newtonsoft.Json behavior.
runtime/src/libraries/System.Text.Json/tests/Serialization/PropertyVisibilityTests.cs Lines 386 to 387 in 766572f
runtime/src/libraries/System.Text.Json/tests/Serialization/PropertyVisibilityTests.cs Lines 395 to 396 in 766572f
runtime/src/libraries/System.Text.Json/tests/Serialization/PropertyVisibilityTests.cs Lines 410 to 411 in 766572f
wrt. how we differ - in Newtonsoft.Json, property name conflicts at different type-hierarchy levels that are not caused by deriving or the new keyword are allowed. So, properties on more derived types win. In System.Text.Json, property name conflicts are only valid when caused by deriving or the new keyword. runtime/src/libraries/System.Text.Json/tests/Serialization/PropertyVisibilityTests.cs Line 427 in 766572f
|
This means all CLR naming "conflicts" are OK, but naming conflicts through |
@@ -4,6 +4,7 @@ | |||
|
|||
using System.Collections.Generic; | |||
using System.Diagnostics; | |||
using System.Diagnostics.CodeAnalysis; |
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.
Is this necessary (I didn't see any use of nullability attributes)?
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.
No - will remove. I used a nullability attribute in a helper in an earlier iteration of this change.
Yes. |
Contributes to fixing #37640. Will leave the issue open until the fix is confirmed in app compat. cc @DotNetAppCompatFeiWang
#36936 made a change so that the serializer ignores virtual properties when a derived property that hid them is ignored (with
[JsonIgnore]
) and there's a JSON property name collision.The failing scenario in #37640 makes it clear that we need to ignore virtual properties when a derived property that hid them is ignored, whether or not there's a property name collision. This is to avoid serializing content that the caller explicitly marked to be ignored.