-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Open
Labels
AnalysisIssues related to static analysis (vet, x/tools/go/analysis)Issues related to static analysis (vet, x/tools/go/analysis)ProposalProposal-Accepted
Milestone
Description
Marking a struct field of type time.Time
as json omitempty has no effect. You must use a *time.Time
for it to work (which is wire compatible). Vet should detect this situation and perhaps suggest *time.Time
instead.
- Frequency: According to @dsnet, this is a common source of package json confusion. This situation has spawned a handful of proposals: proposal: encoding/json, encoding/xml: support zero values of structs with omitempty #11939, proposal: encoding/json: "nonil" struct tag to marshal nil slices and maps as non-null #27589, encoding/json: add omitzero option #45669.
- Precision: There is no sensible interpretation of omitempty on a time.Time field.
- Severity: Depends on how important the omitempty behavior is. In the case that I just encountered, it was moderate severity. In the most likely scenario, it is resource waste (bandwidth, storage).
This might be reasonably extended to any struct type; see the linked omitzero proposals for more discussion. If an omitzero proposal is accepted, vet could switch to suggesting the use of omitzero rather than suggesting a pointer type.
OneOfOne, timothy-king, Dr-Terrible, sudo-bmitch, ainar-g and 2 more
Metadata
Metadata
Assignees
Labels
AnalysisIssues related to static analysis (vet, x/tools/go/analysis)Issues related to static analysis (vet, x/tools/go/analysis)ProposalProposal-Accepted
Type
Projects
Status
Accepted