NSwag: The ignore condition 'JsonIgnoreCondition.WhenWritingNull' is not valid on value-type member
Hello,
Since version 13.16.0 of Nswag, the following attribute is added to all properties of the generated models when generating the C# clients.
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
This causes the following errors on value type properties.
The ignore condition 'JsonIgnoreCondition.WhenWritingNull' is not valid on value-type member 'LanguageId' on type 'User'. Consider using 'JsonIgnoreCondition.WhenWritingDefault'.
Is there a way to disable the generation of this attribute?
Kind regards, Jorsi
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 33
- Comments: 23 (1 by maintainers)
Commits related to this issue
- Downgrade NSwag.MSBuild due to https://github.com/RicoSuter/NSwag/issues/4012 — committed to jellyfin/jellyfin-sdk-csharp by crobibero 2 years ago
Any update on this? The latest package version has had a show stopping issue for almost 3 months now.
we are also experiencing this issue, however rolling back to 13.15.10 has resolved it for now.
How can i opt-out of this bevaviour or force my values?
Before these changes there was no attribute what so ever (so the default behaviour of STJ i assume). Then it was briefly System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull. And now its different again. This is kinda breaking…
This breaks alot of my connectors, assumptions and tests. Often a called backend service is not that easily to change.
From my current understanding of the code base its now either “WhenWritingDefault” or “Never” depending of the property if “required” or not. And nothing else?
The broken stuff is also subtle. Took me some time to find out the an INT 0 was not send because the whole property was disregarded because it was not required.
It looks like rolling back to 13.15.10 resolves this issue for the time being.
Same here.
@RicoSuter - Thanks for the fix!! I just hit this issue with NSwag.MSBuild. Could we get an updated version of that package published to Nuget?
I used this code to circumvent the problem at runtime.
Same with v13.16.1. Following solution resolved the issue :