Skip to content

Commit 3dabd1e

Browse files
author
Divjot Arora
committed
Clarify omitempty documentation (#579)
1 parent e630617 commit 3dabd1e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

bson/doc.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,13 @@
9595
// to configure behavior:
9696
//
9797
// 1. omitempty: If the omitempty struct tag is specified on a field, the field will not be marshalled if it is set to
98-
// the zero value. By default, a struct field is only considered empty if the field's type implements the Zeroer
99-
// interface and the IsZero method returns true. Struct fields of types that do not implement Zeroer are always
100-
// marshalled as embedded documents. This tag should be used for all slice and map values.
98+
// the zero value. Fields with language primitive types such as integers, booleans, and strings are considered empty if
99+
// their value is equal to the zero value for the type (i.e. 0 for integers, false for booleans, and "" for strings).
100+
// Slices, maps, and arrays are considered empty if they are of length zero. Interfaces and pointers are considered
101+
// empty if their value is nil. By default, structs are only considered empty if the struct type implements the
102+
// bsoncodec.Zeroer interface and the IsZero method returns true. Struct fields whose types do not implement Zeroer are
103+
// never considered empty and will be marshalled as embedded documents.
104+
// NOTE: It is recommended that this tag be used for all slice and map fields.
101105
//
102106
// 2. minsize: If the minsize struct tag is specified on a field of type int64, uint, uint32, or uint64 and the value of
103107
// the field can fit in a signed int32, the field will be serialized as a BSON int32 rather than a BSON int64. For other

0 commit comments

Comments
 (0)