-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
YAML | JSON.mapping presence: true option. #4843
YAML | JSON.mapping presence: true option. #4843
Conversation
Allows to distinguish absence of key-value pairs vs null values.
bcdf497
to
1a35ccc
Compare
@ysbaddaden @RX14 I understand your concern that this bloats The nice thing about this is that you retain type safety and you keep the information of which keys were present in the original JSON. You can of course use As a comparison, see this answer for how to do it in Go: you basically have to map the field to the raw bytes that came in the JSON, and then you have to parse it again... so you lose type-safety, and it's more tedious. I think it's nice if there's a built-in way to do it in the standard library. As for a real use case: imagine an HTTP endpoint that accepts updates to an object. The client can specify which fields to update, and to clear a field sends (but of course, like every PR since a few weeks ago, this has to be accepted by a few members, so my opinion alone doesn't count anymore: and that's very good) |
IMHO this is too much, but I don't use X.mapping myself, and since there are valid use cases, then it's acceptable. |
I can see the usecase much more clearly now, so yes it's a 👍 from me. Would be nice if there was a cleaner way to do this but there probably isn't unless we implement custom attributes and I have my own reservations about slinging around too much metadata. |
Is there really a need for another option if it's only usable with |
Yes, we need another option just because we have And |
Allows to distinguish absence of key-value pairs vs null/default values.
Fixes #4840.
Proposed by @asterite, I just added the specs.