Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

OmitIfEmpty encoding option issue with documentation #28

Open
jhg03a opened this issue Feb 24, 2018 · 1 comment
Open

OmitIfEmpty encoding option issue with documentation #28

jhg03a opened this issue Feb 24, 2018 · 1 comment

Comments

@jhg03a
Copy link

jhg03a commented Feb 24, 2018

I ran into an issue that was annoying to track down and I'm not sure I entirely get it. I was using jsonenums as part of a nested struct slice, and explicitly setting the json field name & setting the omitifempty flag. My observation was that if I built an instance of that struct explicitly setting the value to be iota 0 as documented in the shirtsize example project, the value during encoding would be removed entirely. If I removed the omitifempty flag, the proper value would show up. Likewise I could also work around it by just adding 1 to the iota const. It may be worth further investigation and/or a simple documentation update to warn people about this.

I was able to track it as far as here in the golang encode library. My gut is telling me somewhere there is a confusion between an iota value of 0 and a nil which is what I expect omitifempty to apply to.

@dzintars
Copy link

Gosh... same issue there! :)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants