Skip to content

Commit 9d9808f

Browse files
author
Divjot Arora
committed
Clarify omitempty documentation (#579)
1 parent 4b6f555 commit 9d9808f

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
@@ -103,9 +103,13 @@
103103
// to configure behavior:
104104
//
105105
// 1. omitempty: If the omitempty struct tag is specified on a field, the field will not be marshalled if it is set to
106-
// the zero value. By default, a struct field is only considered empty if the field's type implements the Zeroer
107-
// interface and the IsZero method returns true. Struct fields of types that do not implement Zeroer are always
108-
// marshalled as embedded documents. This tag should be used for all slice and map values.
106+
// the zero value. Fields with language primitive types such as integers, booleans, and strings are considered empty if
107+
// their value is equal to the zero value for the type (i.e. 0 for integers, false for booleans, and "" for strings).
108+
// Slices, maps, and arrays are considered empty if they are of length zero. Interfaces and pointers are considered
109+
// empty if their value is nil. By default, structs are only considered empty if the struct type implements the
110+
// bsoncodec.Zeroer interface and the IsZero method returns true. Struct fields whose types do not implement Zeroer are
111+
// never considered empty and will be marshalled as embedded documents.
112+
// NOTE: It is recommended that this tag be used for all slice and map fields.
109113
//
110114
// 2. minsize: If the minsize struct tag is specified on a field of type int64, uint, uint32, or uint64 and the value of
111115
// 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)