-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Eliminated info creation for non-public properties #2278
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
Conversation
| CreateObject = options.MemberAccessorStrategy.CreateConstructor(type); | ||
|
|
||
| PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); | ||
| PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public); |
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.
We should add some tests ensuring that the serializer doesn't deserialize/serialize non-public properties under any circumstance including:
- when a derived type adds a non-public
newproperty which collides with a public property defined on the parent - when there are property name collisions between public/non-public properties due to
[JsonPropertyName] - when there are property name collisions between public/non-public properties due to
JsonNamingPolicy
all such tests should have variants checking that public properties that are [JsonIgnore]'d are not accidentally (de)serialized due to mismatching JsonPropertyInfo with a colliding non-public member.
https://dotnetfiddle.net/2BD7bK goes over a few expecations.
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.
@YohDeadfall - let us know if you are up for adding the tests in this PR based on what @layomia suggested (its fine if you prefer someone else take that on, but will certainly be helpful to add).
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.
Though about improving tests, but as a separate PR (would like to do some cleanup and improvements for better coverage/understanding). Will take a look at this tomorrow.
|
@maryamariyan - is the bot not able to auto-label PRs with areas or was this a one-off issue? |
|
From #2246 (comment)
@steveharter, don't we have tests for that case? This PR removed the flag and the existing tests are passing in CI. Either it wasn't needed, or we have a test gap. |
Sorry I misspoke. BindingFlags.Public works fine with non-pulic setters. |
|
Merging this. Next steps from this PR are
These tasks help establish a pattern and expectations for member collision handling which is needed en-route field support. @YohDeadfall please let us know if you can include these in your plans for tests/coverage over the next couple of days; otherwise I'm happy to get this work started. |
|
@layomia, started to work on the first already. Since tests cover the issue, I can work on it too. |
Since JSON serialization doesn't support private properties at all, there is no need to create info for them. Previously discussed in #2242.