Skip to content

Commit 79e5ea4

Browse files
committed
add docs
Change-Id: Ic68413b71d1f605d131c7f909839e565198f074b
1 parent 4df0252 commit 79e5ea4

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
When marshaling, a struct field with the new `omitzero` option in the struct field
2+
tag will be omitted if its value is zero. If the field type has an `IsZero() bool`
3+
method, that will be used to determine whether the value is zero. Otherwise, the
4+
value is zero if it is [the zero value for its type](/ref/spec#The_zero_value).
5+
If both `omitempty` and `omitzero` are specified, the field will be omitted if the
6+
value is either empty or zero (or both).

src/encoding/xml/marshal.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ const (
6060
// if the field value is empty. The empty values are false, 0, any
6161
// nil pointer or interface value, and any array, slice, map, or
6262
// string of length zero.
63+
// - a field with a tag including the "omitzero" option is omitted
64+
// if the field has a zero value, according to rules:
65+
// 1) If the field type has an "IsZero() bool" method, that will be used to
66+
// determine whether the value is zero.
67+
// 2) Otherwise, the value is zero if it is the zero value for its type.
68+
// If both "omitempty" and "omitzero" are specified, the field will be omitted
69+
// if the value is either empty or zero (or both).
6370
// - an anonymous struct field is handled as if the fields of its
6471
// value were part of the outer struct.
6572
// - an anonymous struct field of interface type is treated the same as having

0 commit comments

Comments
 (0)