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

allow BSON null values to decode into non-nilable Go types

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.3.0
    • Affects Version/s: None
    • Component/s: BSON
    • Fully Compatible

      purpose:  fix `can not decode null into a xxx type` issues.

      current possible solution:

      1. change data in mongodb
      2. use pointer type, e.g. define field as type `*string`  but not  `string`
      3. customize the bson decoder

      solution 1 is very difficult to do if considering team cooperation.

      solution 3 is too heavy for such small requirement.

      solution 2 is most acceptable so far, but it will make code ugly, because the compromise between field type and decoder

      i propose a new tag property:

      `skipnull`: skip null value(don't touch this field, or set to zero value?) when unmarshaling

       

      this propose assume that in many cases, null value and non-exist is the same thing in mongodb. feel free to close this issue if the assumption don't make much sense 

       

      EDIT: We've gotten multiple requests to allow BSON null values to decode into Go types that can't necessarily be nil (e.g. string). We should change our default decoders to accept BSON null values so there's no user configuration required to enable this feature. I'm adding this to the mgo BSON registry epic to help us track the ticket, but it will be enabled as a default for all codecs, not just in the mgo registry.

            Assignee:
            divjot.arora@mongodb.com Divjot Arora (Inactive)
            Reporter:
            zzn zzn
            Votes:
            4 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: