-
Type: Improvement
-
Resolution: Won't Fix
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: BSON
-
None
Currently the Go BSON library considers a private struct field one that both has a non-empty PkgPath and is not anonymous (i.e. not embedded). For example:
structField.PkgPath != "" && !structField.Anonymous
However, that logic disagrees with the Go reflect definition of a private struct field, which only considers PkgPath != "". As implemented in the StructCodec code, the difference only affects the behavior of the AllowUnexportedFields option, but the result is that the AllowUnexportedFields option only applies to anonymous fields in structs.
That behavior seems to be inspired by similar logic in the mgo BSON code which incorrectly considers all anonymous fields non-private.
Definition of done:
- Update the AllowUnexportedFields option to consider all private fields valid, not just anonymous ones.
- Update the mgocompat registry to use a struct encoder that doesn't rely on the AllowUnexportedFields option.