Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2797

Treat named and anonymous private struct fields the same when marshaling

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            matt.dale@mongodb.com Matt Dale
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: