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

`omitempty` never applies to arrays

    • Type: Icon: Improvement Improvement
    • Resolution: Works as Designed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Go Drivers
    • 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?

      Detailed steps to reproduce the problem?

      Run the following Go program:

      import (
      	"fmt"
      
      	"github.com/google/uuid"
      	"go.mongodb.org/mongo-driver/bson"
      )
      
      func main() {
      	myStruct := struct {
      		MyUUID uuid.UUID `bson:",omitempty"`
      	}{}
      
      	raw, _ := bson.Marshal(myStruct)
      
      	fmt.Printf("BSON: %s", string(raw))
      }
      

      Note that `myuuid` prints, indicating that Marshal() is creating an empty for the zero-value array.

      Definition of done: what must be done to consider the task complete?

      The array shouldn’t be marshaled since it’s a zero-value.

      The exact Go version used, with patch level:

      1.22 (unknown patch level)

      The exact version of the Go driver used:

      1.15

      Describe how MongoDB is set up. Local vs Hosted, version, topology, load balanced, etc.

      n/a

      The operating system and version (e.g. Windows 7, OSX 10.8, ...)

      n/a

      Security Vulnerabilities

      n/a

            Assignee:
            preston.vasquez@mongodb.com Preston Vasquez
            Reporter:
            felipe.gasper@mongodb.com Felipe Gasper
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: