encoding/json: invalid use of ,string struct tag, trying to unmarshal "" into int #41731
Labels
FrozenDueToAge
WaitingForInfo
Issue is not actionable because of missing required information, which needs to be provided.
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?
Unmarshal json (https://play.golang.org/p/Ka8kdddUHKu):
What did you expect to see?
Since val is
""
, the error as such is expected, however I would expect theomitempty
to make a difference and hence returnnil
error. According to https://golang.org/pkg/encoding/json/:What did you see instead?
Error: invalid use of ,string struct tag, trying to unmarshal "" into int
Reasoning
To give flexibility in handling external json input it is preferable to handle the
omitempty
tag before handling further validations likestring
. In this case the order seems to be different.If effect,
,string,omitempty
should allow""
to be unmarshaled into numeric zero values.UPDATE I realize this might indeed be more a proposal as
omitempty
seems to be documented and take effect only for marshaling but not unmarshaling.The text was updated successfully, but these errors were encountered: