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

Handle nil properties of a struct in the BSON encoder

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 0.0.3
    • Affects Version/s: 0.0.2
    • Component/s: None
    • None

      The BSON encoder does not handle struct properties that can be nil. If it does encounter a nil struct property it returns an error when it should encode that value into a BSON Null.

      To fix this:

      • Update underlyingVal to check if the value is nil when it's Kind is either a reflect.Ptr or a reflect.Interface. If it is, don't return the underlying Elem, instead return the pointer or interface.
      • In encodeMap, encodeSlice, encodeSliceAsArray, and encodeStruct, after calling underlyingVal, if the kind is an interface, map, pointer, or slice, and it is nil, return a BSON Null type.

            Assignee:
            Unassigned Unassigned
            Reporter:
            kris.brandow@mongodb.com Kristofer Brandow (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: