-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add possibility to ignore JsonElement during serializing. #512
Comments
To summarize: The suggestion is to treat a JsonElement property with no value(JsonValueKind.Undefined) the same as a property with a null value, when JsonSerializerOption IgnoreNullValues=true (or adding a new JsonSerializerOption, for example IgnoreUndefinedValues=true). |
A Since you want to ignore As you mention in #779 (comment), conditional ignore semantics, global and/or per-property, "ignore when default", would also help here. |
I agree. Is there a reason why you can't use This specific issue isn't actionable and we have existing issues to enable more flexible ignore semantics, so I consider this issue as a duplicate of the others that @layomia linked to. |
@ahsonkhan There is no reason why I can´t use JsonElement? at the moment and this is what I ended up doing. If there will be other possibilities in the future I could change this(if it will be better in some way). I would like to thank you all for the great work you do with dotnet, I also think the new S.T.J is a good addition to the platform and it works great! |
Great. That sounds good.
Appreciate it. We have a few up-for-grabs issues if you are interested in contributing :) |
I am trying to use the new System.Text.Json to Serialize and Deserialize messages based on the JSONRPC2.0 specification(https://www.jsonrpc.org/specification). In the specification there are JSON properties that may be omitted, for example the params property.
The params property value could be any JSON value, which I think maps good to the JsonElement type.
However, when serializing, and the params property is omitted, an InvalidOperationException occurs. Is this by design? Or would it be a good idea to treat the ValuKind.Undefined the same as a null value with IgnoreNullValues=true? Perhaps a new setting IgnoreUndefinedValues=true?
I created a simple example program to reproduce this issue:
Using JsonElement? or object instead works, but I think that using JsonElement will be best if possible. Because, If using object instead, I must unbox it to a JsonElement after deserializing.
The text was updated successfully, but these errors were encountered: