Skip to content

Commit 1470c69

Browse files
matthewdaleblink1073
authored andcommitted
GODRIVER-3138 Improve omitempty tag documentation. (mongodb#1739)
(cherry picked from commit 4786941)
1 parent 63f79c0 commit 1470c69

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

bson/doc.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,13 @@
107107
// The name may be empty in order to specify options without overriding the default field name. The following options can
108108
// be used to configure behavior:
109109
//
110-
// 1. omitempty: If the omitempty struct tag is specified on a field, the field will be omitted from the marshaling if
111-
// the field has an empty value, defined as false, 0, a nil pointer, a nil interface value, and any empty array,
112-
// slice, map, or string.
113-
// NOTE: It is recommended that this tag be used for all slice and map fields.
110+
// 1. omitempty: If the "omitempty" struct tag is specified on a field, the field will not be marshaled if it is set to
111+
// an "empty" value. Numbers, booleans, and strings are considered empty if their value is equal to the zero value for
112+
// the type (i.e. 0 for numbers, false for booleans, and "" for strings). Slices, maps, and arrays are considered
113+
// empty if they are of length zero. Interfaces and pointers are considered empty if their value is nil. By default,
114+
// structs are only considered empty if the struct type implements [bsoncodec.Zeroer] and the IsZero
115+
// method returns true. Struct types that do not implement [bsoncodec.Zeroer] are never considered empty and will be
116+
// marshaled as embedded documents. NOTE: It is recommended that this tag be used for all slice and map fields.
114117
//
115118
// 2. minsize: If the minsize struct tag is specified on a field of type int64, uint, uint32, or uint64 and the value of
116119
// the field can fit in a signed int32, the field will be serialized as a BSON int32 rather than a BSON int64. For

0 commit comments

Comments
 (0)