-
Notifications
You must be signed in to change notification settings - Fork 45
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
Inconsistent behavior of nulls? #151
Comments
Signed-off-by: Samuel Berger <[email protected]>
I can confirm the bug. I tried to fix it #153 |
The reason for the current behavior is to preserve the ability to round-trip: if you serialize But I see your point and I am open to allow this as an option. I'd rather make it an explicit one though. I think this deserves a new fluent option. Tentative name: (We could also make it an optional value passed to |
Ok, I see. First, this bug is about In our case it hit customers using our public API - so my reasoning about the second point, nested option types, is also seen through that lens: using the serializer at application boundary to be called from third party: In my experience, modeling application code by nesting options is rare, but of course, valid (like having two reasons for presence/absence of something, like table having column yes/no and the value itself can be absent). But even then, beeing more explicit by using different types, probably makes things easier - like you did with the On the other hand when serializing your model to JSON, nested option types cannot be represented with nulls. In my case, fixing the bug in either way would be fine, as nested option types in our public API would never occur. But still my opinion is: serializing options as nulls implies 'loss of information' and that is intended and fine :) Is the round-trip ability based on a real use case scenario? Would be a happy to learn about it. |
Any progress on this? I'm consuming an API where I don't care about round-trip serialization at all. |
[#151] Add option to deserialize both null and missing as None
This is released in v1.3.13: JsonFSharpOptions.Default()
.WithSkippableOptionFields(SkippableOptionFields.Always, deserializeNullAsNone = true) |
Now that
WithSkippableOptionFields
is implemented (thank you!) I can generate what looks like confusing results:What looks strange to me is the first
stringOption
. Passing null renders "Some null". How do I get "None" instead? Is my only choice to omit the field from the input? If so, why the inconsistency between that, and a null that appears inside a sequence?The code I used:
The text was updated successfully, but these errors were encountered: