Repository navigation
fix: Correct model nullability and make strict JSON deserialization opt-in - #130
Conversation
…torParametersDefault` globally
…ctorParametersDefault` locally
HofmeisterAn
left a comment
There was a problem hiding this comment.
Thanks for the issue and the PR. The model classes are generated by tools/specgen, and the bug is there. It only marks pointers and omitempty fields as nullable, but Go also writes nil maps and slices as null.
I think it's better to fix the generator than to turn the switches off in the library, because that would hide the wrong annotations. It would also make them correct at compile time for consumers.
Yes, if we can make the annotations accurate, that would be best. And once they are accurate, we would want to turn these switches on, as in the first commit here (they're off by default for backwards compatibility). |
|
I thought about this once more, and we probably need a mixed approach. Improve the nullable information in the generator and make the library more resilient to global STJ configurations. This isn't only about wrong annotations in the library. There are many different container runtime backends and API versions, and they may not all follow the same nullability, so an unexpected null shouldn't fail a whole call. |
Workaround for #129.
RespectNullableAnnotationsDefaultandRespectRequiredConstructorParametersDefaultglobally in this repo. (The tests in this repo targeting .NET 9 or higher fail at this commit.)JsonSerializerOptions.RespectNullableAnnotationsandJsonSerializerOptions.RespectRequiredConstructorParametersin code for theJsonSerializerinstance used in this library when targeting .NET 9 or higher, which takes precedence over the global switches in this repo and in any consuming code.If and when the nullable annotations are fixed, the two explicit disablings should be removed.