Skip to content

JsonSerializerOptions.IgnoreReadOnlyProperties ignores collections #67514

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

Closed
famda opened this issue Apr 3, 2022 · 2 comments
Closed

JsonSerializerOptions.IgnoreReadOnlyProperties ignores collections #67514

famda opened this issue Apr 3, 2022 · 2 comments

Comments

@famda
Copy link

famda commented Apr 3, 2022

Hey all,
I was playing around with JsonSerializerOptions and I noticed that collections are being ignored by the property JsonSerializerOptions.IgnoreReadOnlyProperties.
It continues serializing the properties.

What this does is that we need to bring an unecessary dependency to our models (JsonIgnoreAttribute) which, for me, makes no sense.

And the alternative of creating custom json converters is quite painfull.

Noticed that an issue was already created/closed without a clear answer to it.
System.Text.Json: JsonSerializerOptions.IgnoreReadOnlyProperties being ignored #37599

What options do we have to solve this issue?

@ghost ghost added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Apr 3, 2022
@ghost
Copy link

ghost commented Apr 3, 2022

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

Hey all,
I was playing around with JsonSerializerOptions and I noticed that collections are being ignored by the property JsonSerializerOptions.IgnoreReadOnlyProperties.
It continues serializing the properties.

What this does is that we need to bring an unecessary dependency to our models (JsonIgnoreAttribute) which, for me, makes no sense.

And the alternative of creating custom json converters is quite painfull.

Noticed that an issue was already created/closed without a clear answer to it.
System.Text.Json: JsonSerializerOptions.IgnoreReadOnlyProperties being ignored #37599

What options do we have to solve this issue?

Author: famda
Assignees: -
Labels:

area-System.Text.Json, untriaged

Milestone: -

@eiriktsarpalis
Copy link
Member

What this does is that we need to bring an unecessary dependency to our models (JsonIgnoreAttribute) which, for me, makes no sense.

Agreed, but at this point changing the behavior would likely be a breaking change. The functionality in #63686 should provide a configuration mechanism alternative to applying JsonIgnore attributes.

@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Apr 4, 2022
@ghost ghost locked as resolved and limited conversation to collaborators May 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants