Skip to content
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

I want to use JsonIgnore only when deserializing with System.Text.Json #34404

Closed
neelabo opened this issue Apr 1, 2020 · 4 comments
Closed
Labels
area-System.Text.Json backlog-cleanup-candidate An inactive issue that has been marked for automated closure.
Milestone

Comments

@neelabo
Copy link

neelabo commented Apr 1, 2020

I use Json for the configuration file of the application.
The format of the configuration file changes with the version upgrade of the application, and certain properties may become invalid.
In such cases, we need to make it readable for compatibility with the old configuration file, but we do not want to output to the new configuration file.
I want to be able to do this.

  • If it is a JsonIgnore attribute, both serialization and deserialization will be invalid.
  • With the IgnoreNullValues ​​option, properties that you want to output as null will also disappear.
  • "Conditionally ignore a property" is too heavy for the purpose.

Ideally, doing something like [JsonIgnore(IgnoreDeserialize=false)] would allow for control of serialization and deserialization.

Please consider it.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Apr 1, 2020
@ghost
Copy link

ghost commented Apr 1, 2020

Area Owners

@layomia, @steveharter, @jozkee

@layomia
Copy link
Contributor

layomia commented Apr 2, 2020

The serializer's features are designed so that data can roundtrip, i.e serialize -> deserialize -> serialize gives the original result. This is why JsonIgnoreAttribute is applied to both serialization and deserialization.

Having a way to specify whether the attribute is applied to serialization/deserialization was considered (see #30687 (comment)), but it wasn't needed by most people.

A future work-around here is to implement a custom converter (for the property) which does the desired null-handling specific to reading and writing. This is blocked by #34439 (planned for 5.0),

@layomia layomia removed the untriaged New issue has not been triaged by the area owner label Apr 2, 2020
@layomia layomia added this to the Future milestone Apr 2, 2020
@ghost
Copy link

ghost commented Oct 15, 2021

Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

This process is part of the experimental issue cleanup initiative we are currently trialing in a limited number of areas. Please share any feedback you might have in the linked issue.

@ghost
Copy link

ghost commented Nov 5, 2021

This issue will now be closed since it had been marked no recent activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

@ghost ghost closed this as completed Nov 5, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Dec 5, 2021
@eiriktsarpalis eiriktsarpalis added the backlog-cleanup-candidate An inactive issue that has been marked for automated closure. label Feb 18, 2022
@ghost ghost removed the no-recent-activity label Feb 18, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json backlog-cleanup-candidate An inactive issue that has been marked for automated closure.
Projects
None yet
Development

No branches or pull requests

4 participants