-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Added opt-in flag to enable non-public members #2246
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
| { | ||
| public JsonSerializerOptions() { } | ||
| public bool AllowTrailingCommas { get { throw null; } set { } } | ||
| public bool AllowPrivateProperties { get { throw null; } set { } } |
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.
Since this is an API change, it would need to go through API review. Also, I don't think we want to support non-public properties within the JsonSerializer. I haven't seen evidence that a lot of folks want this feature.
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.
An issue with supporting non-public is that it won't work with code-gen \ AOT scenarios where we can't use reflection.
| { | ||
| CreateObject = options.MemberAccessorStrategy.CreateConstructor(type); | ||
|
|
||
| PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); |
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.
I believe the only fix here is to remove the BindingFlags.NonPublic flag. It's not conveying the intent of the serializer and likely just an oversight (maybe copy/paste error). In reality, non-public properties are not supported.
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.
I believe NonPublic is necessary to support public getters and non-public setters.
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.
Responded in the PR that's removing it: #2278 (comment)
|
This flag is not necessary and I don't believe there is a breaking change here. See #2242 (comment). To me, we should just fix the binding flags typo in this PR, but the other changes should be reverted. |
|
Closing this in favor of #2278. Speaking about private properties, I think there is no need in them too. It's a very rare which can be resolved via a custom converter or by adding parametrized |
Fixes #2242. It's a breaking change.
Unfortunately, not able to test locally because of: