Skip to content
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

cmd/go: add vet check for json/xml omitempty struct tags on non-basic types #63539

Closed
andig opened this issue Oct 14, 2023 · 1 comment
Closed

Comments

@andig
Copy link
Contributor

andig commented Oct 14, 2023

It's easy to make the mistake of adding omitempty struct tags like this (example from https://github.com/golang/oauth2/blob/master/token.go#L50C2-L50C44.):

Expiry time.Time `json:"expiry,omitempty"`

Currently, this does nothing. With encoding/json/v2 it might become omitzero.

I suggest to add a vet check flagging omitempty as error when added on time.Time non-basic types according to encoding/json's isEmptyValue (https://github.com/golang/go/pull/63533/files#diff-01d931f6d3bbaef911876952770a164229fe8d659b9007f4be9fc1ea12d20abeR306).

@andig andig added the Proposal label Oct 14, 2023
@andig andig changed the title cmd/go: add vet check for json:omitempty on time.Time cmd/go: add vet check for json:omitempty on non-basic types Oct 14, 2023
@andig andig changed the title cmd/go: add vet check for json:omitempty on non-basic types cmd/go: add vet check for json/xml omitempty struct tags on non-basic types Oct 14, 2023
@seankhliao
Copy link
Member

Duplicate of #51261

@seankhliao seankhliao marked this as a duplicate of #51261 Oct 14, 2023
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Oct 14, 2023
@golang golang locked and limited conversation to collaborators Oct 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants