Skip to content

Conversation

@YohDeadfall
Copy link
Contributor

Fixes #2242. It's a breaking change.

Unfortunately, not able to test locally because of:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(231,5): error MSB8065: Custom build for item "D:\Repos\dotnet\runtime\artifacts\obj\native\netcoreapp5.0-Windows_NT-Debug-x64\CMakeFiles\fe7a6c5df725904c22996c4fd4406c45\INSTALL_force.rule" succeeded, but specified output "d:\repos\dotnet\runtime\artifacts\obj\native\netcoreapp5.0-windows_nt-debug-x64\cmakefiles\install_force" has not been created. This may cause incremental build to work incorrectly. [D:\Repos\dotnet\runtime\artifacts\obj\native\netcoreapp5.0-Windows_NT-Debug-x64\install.vcxproj] [D:\Repos\dotnet\runtime\src\libraries\Native\build-native.proj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(231,5): error MSB8065: Custom build for item "D:\Repos\dotnet\runtime\artifacts\obj\native\netcoreapp5.0-Windows_NT-Debug-x64\CMakeFiles\fe7a6c5df725904c22996c4fd4406c45\INSTALL_force.rule" succeeded, but specified output "d:\repos\dotnet\runtime\artifacts\obj\native\netcoreapp5.0-windows_nt-debug-x64\cmakefiles\install_force" has not been created. This may cause incremental build to work incorrectly. [D:\Repos\dotnet\runtime\artifacts\obj\native\netcoreapp5.0-Windows_NT-Debug-x64\install.vcxproj] [D:\Repos\dotnet\runtime\src\libraries\Native\build-native.proj]

{
public JsonSerializerOptions() { }
public bool AllowTrailingCommas { get { throw null; } set { } }
public bool AllowPrivateProperties { get { throw null; } set { } }
Copy link
Contributor

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.

Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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)

@ahsonkhan
Copy link
Contributor

ahsonkhan commented Jan 27, 2020

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.

@YohDeadfall
Copy link
Contributor Author

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 .ctor support.

@YohDeadfall YohDeadfall deleted the non-public-opt-in branch January 28, 2020 12:55
@layomia layomia added this to the 5.0 milestone May 15, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON serializer should not support non-public properties by default

6 participants