diff options
| author | Austin Clements <austin@google.com> | 2024-12-26 18:05:07 -0500 |
|---|---|---|
| committer | Austin Clements <austin@google.com> | 2024-12-27 08:33:01 -0800 |
| commit | 539202f32b361523f2a18b1481bcd06a136a3c16 (patch) | |
| tree | 43d607a43aa407ebd33acb951145f1c68b47cd1e | |
| parent | b27bc76cb1a963535ce820088a71e78f3c5ab918 (diff) | |
| download | go-x-website-539202f32b361523f2a18b1481bcd06a136a3c16.tar.xz | |
_content/doc/go1.24: motivate omitzero
Change-Id: I4327eff0080bc279bb0c686d3c8266b05af3de95
Reviewed-on: https://go-review.googlesource.com/c/website/+/638564
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
| -rw-r--r-- | _content/doc/go1.24.md | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/_content/doc/go1.24.md b/_content/doc/go1.24.md index 169e9268..6f78ce3d 100644 --- a/_content/doc/go1.24.md +++ b/_content/doc/go1.24.md @@ -542,10 +542,15 @@ already implemented `TextMarshaler` and/or `BinaryMarshaler`. #### [`encoding/json`](/pkg/encoding/json/) +<!-- go.dev/issue/45669 --> When marshaling, a struct field with the new `omitzero` option in the struct field tag will be omitted if its value is zero. If the field type has an `IsZero() bool` method, that will be used to determine whether the value is zero. Otherwise, the value is zero if it is [the zero value for its type](/ref/spec#The_zero_value). +The `omitzero` field tag is clearer and less error-prone than `omitempty` when +the intent is to omit zero values. +In particular, unlike `omitempty`, `omitzero` omits zero-valued +[`time.Time`](/pkg/time#Time) values, which is a common source of friction. If both `omitempty` and `omitzero` are specified, the field will be omitted if the value is either empty or zero (or both). |
