Uh oh!
There was an error while loading. Please reload this page.
Fixed serialization of hidden base class members - #32107
Conversation
ad02d69 to
19c48b1Compare
layomia
left a comment
There was a problem hiding this comment.
Just a few more test cases to consider.
Uh oh!
There was an error while loading. Please reload this page.
| @@ -11,6 +11,231 @@ namespace System.Text.Json.Serialization.Tests | |||
| { | |||
| public static class PropertyVisibilityTests | |||
There was a problem hiding this comment.
nit: can you use PascalCase for the tests names where possible and capitalize the first letter after an underscore where needed?
There was a problem hiding this comment.
It's a naming used by EF Core for long test names, but am okay with changing this if you want, but first compare names.
Before: Serialize_base_public_property_on_conflict_with_derived_private
After: SerializeBasePublicPropertyOnConflictWithDerivedPrivate
The first one is more readable while the second looks like encoded data and is hard to read. So are you sure that pascal case is better? I can rename other tests and give them meaningful names instead of current (:
There was a problem hiding this comment.
I do underscore-delimited pascal case chunks in such cases, e.g. Serialize_BasePublicProperty_OnConflictWithDerivedPrivate. The before pattern isn't used anywhere else in this codebase.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| public string MyString { get; set; } = "DefaultValue"; | ||
| [JsonPropertyName(nameof(MyString))] | ||
| internal string ConflictingString { get; set; } = "ConflictingValue"; |
There was a problem hiding this comment.
We need a class variant where this property is public; and a test variant where the conflict spans across two inheritance levels.
| @@ -11,6 +11,231 @@ namespace System.Text.Json.Serialization.Tests | |||
| { | |||
| public static class PropertyVisibilityTests | |||
There was a problem hiding this comment.
We need a couple more tests involving 3 levels of inheritance, particularly where we have collisions on public properties defined at different levels.
90e8a96 to
d08435eCompare
layomia
left a comment
There was a problem hiding this comment.
This PR should fix #30964 as well.
We need tests for the scenarios in #30964 (comment), particularly this case:
publicclassMyClass{// This should be ignored.publicintMyNumber{get;set;}}publicclassMyDerivedClass:MyClass{// This should be (de)serialized.newpublicdoubleMyNumber{get;set;}}| @@ -11,6 +11,231 @@ namespace System.Text.Json.Serialization.Tests | |||
| { | |||
| public static class PropertyVisibilityTests | |||
There was a problem hiding this comment.
I do underscore-delimited pascal case chunks in such cases, e.g. Serialize_BasePublicProperty_OnConflictWithDerivedPrivate. The before pattern isn't used anywhere else in this codebase.
66b899a to
6d95cddCompareYohDeadfall
commented
Mar 26, 2020
@layomia I finally found some time to finish this, but there is one question. Is there any reason to create a This will help with two things:
If an member exists, then it's visible already (at least supports serialization or deserialization separately). If it's in a base class, we will overwrite it. Otherwise, throw an exception. |
6d95cdd to
6c4c9b4Comparedd06a54 to
9748e61Compare9748e61 to
9c90500Compare
layomia
left a comment
There was a problem hiding this comment.
#32107 (review) is yet to be addressed.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
layomia
commented
Apr 11, 2020
Creating a Perhaps we can remove instances where |
layomia
commented
Apr 13, 2020
YohDeadfall
commented
Apr 13, 2020
Thanks, saw this and fixed already (: |
08d24f9 to
dc20062CompareYohDeadfall
commented
Apr 30, 2020
@layomia tests fail, but for unrelated to this PR issue. Should I address it here? |
jozkee
commented
Apr 30, 2020
It seems to me like the test failures are related to this PR since those doesn't fail on master, only here. |
YohDeadfall
commented
Apr 30, 2020
The failing test should not be affected by this PR since it deserializes an object from an empty string. That area isn't touched, but will take a deeper look. |
jozkee
commented
Apr 30, 2020
You removed the changes to JsonClassInfo recently introduced by #34675 |
YohDeadfall
commented
May 7, 2020
This is a breaking change between .NET 3.1 Core/System.Text.Json 4.7.1 and .NET 5/System.Text.Json 5.0.0. Rather than only observing properties visible from the type to be serialized, the serializer looks at the properties for all the base types in the inheritance chain. This means that The conflict would have to be fixed to avoid this exception. The most common way might be to place |
layomia
commented
May 28, 2020
Follow up: the breaking change this PR introduced was mitigated with #36936. |
danmoseley
commented
Jul 24, 2020
@layomia this is labeled breaking change. Can you please open an issue if necessary with https://github.com/dotnet/docs/issues/new?template=dotnet-breaking-change.md I don't see an existing one |
Removing the breaking-change labels from this PR since the breaking change it introduced (#32107 (comment)) has been mitigated/reversed in follow up PRs #36936 & #37720 to avoid breaking the OpenMU app from internal AppCompat runs - #37640. |
Closes#32106.
Closes#30964.