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

Laxing bson "omitempty"

    • Type: Icon: Improvement Improvement
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: 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?

      This is from golang std json:

      The "omitempty" option specifies that the field should be omitted from the encoding if the field has an empty value, defined as false, 0, a nil pointer, a nil interface value, and any empty array, slice, map, or string.
      

      bson "omitempty" tag should do the same behavior as json so that we could reduce the number of pointers in decoding struct types.

      Example:

      struct below

      type xyz struct {
      	Test string `bson:"test,omitempty"`
      }
      

      won't work with this "bson" data:

      {"test":null}
      

      but will work fine with golang std json: https://play.golang.org/p/q-Wnr81Pu3b

            Assignee:
            Unassigned Unassigned
            Reporter:
            khoa@getlocalmeasure.com khoa pham
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: