The Encoder configuration OmitZeroStruct (and corresponding StructCodec.EncodeOmitDefaultStruct) currently only considers values for exported struct fields when evaluating the "omitempty" struct tag. If a private struct field is a non-zero value, the Encoder will still omit the value when using "omitempty". That is surprising behavior because it deviates from the standard Go equality rules, which consider exported and private struct fields. Update the logic to instantiate a zero-value struct and use the standard Go comparison logic to check if the given struct is the zero value.
Definition of done:
- Update the logic in isZero to do the following if Encoder.OmitZeroStruct is enabled:
return !v.IsValid() || v.IsZero()
- Update documentation on Encoder.OmitZeroStruct to remove the note about only exported struct fields.
- Update the test case in TestIsZero
- is related to
-
GODRIVER-2765 Add an "omitzero" BSON struct tag
- Backlog