encoding/json: inconsistent distinction between omitted, null and non-null values #44023
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/04udQzPSPKK
Background: My model contains optional values, e.g.
Foo *string
.With a JSON based patch method I want to deal with these three cases:
foo
(omitted) -> the fieldFoo
of the model is not changed.foo
, this is null -> the fieldFoo
of the model is changed to null.foo
field, this is non-zero -> theFoo
field of the model is set to the non-zero value.What did you expect to see?
What did you see instead?
In other words, unmarshalling does not distinguish between omitted and null elements, although we have explicitly specified
omitempty
. The other direction (marshalling) works perfectly.Unlike #11939, a basic data type of the builtin package (**string) is affected here.
The text was updated successfully, but these errors were encountered: