Skip to content

JsonSerializerOptions.IgnoreReadOnlyProperties ignores collections #67514

Closed

Description

@famda

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?

Activity

  1. ghost added
    untriaged
    on Apr 3, 2022
  2. eiriktsarpalis commented on Apr 4, 2022

    @eiriktsarpalis
    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.

  3. ghost removed
    untriaged
    on Apr 4, 2022
  4. ghost locked as resolved and limited conversation to collaborators on May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions