-
Notifications
You must be signed in to change notification settings - Fork 11
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
Omitting a value that marshals into null
isn't possible?
#5
Comments
Hello To clarify, the error you're getting is returned by this function because the value returned by your Now, regarding the underlying question about the Since the |
Hm, maybe it'd be wise to have this as optional behaviour via encoder options? |
It would make sense to omit values that equals |
Sure, I'll check it out and get back to you. |
@Bios-Marcel see 45899e5 |
Thanks .... I completely forgot about the fact I wanted to do this. Sorry :< |
Hey,
I've tried to replace
encoding/json
with jettison, since jettison has theomitnil
tag.There are certain fields that I am using a custom type for. The idea behind the type is to allow a HTTP request to set a field to
null
via aPATCH
request, but not automaticallynull
all omitted fields. For that to work, null fields must not be see as empty when unmarshalling. However, when marshalling, these null-values have no worth and should be omitted. Is something like that possible?Let's say you had the following type:
If you now had a resource where both
A
andB
already had a value ofHello
and you'd send the following request:Then field
A
should be nulled, whileB
will stay unchanged, since A was explicitly defined, but B was not.The easy solution would be to make two versions of all structs. One for requests and one for replies, however I think that isn't desirable, as it bloats the code and doesn't allow sharing code to work on these structs.
Here's a small example. The second case will panic with
json: error calling MarshalJSON for type *flows_service.NullableString: json: invalid value
.The text was updated successfully, but these errors were encountered: