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

Unmarshaling BSON into a struct with interface fields containing concrete value types doesn't work as expected.

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.0.0
    • Affects Version/s: 1.4.4
    • Component/s: BSON
    • None
    • Environment:
      go 1.15.6
    • Major Change
    • Not Needed
    • 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?

      when set slice point to struct. bson can not decode value in to the origin object

      compare to json package. json works well

       

      // code placeholder
      
      type Data struct {
         Name string `bson:"name"`
      }
      
      type Demo struct {
         Total []Total `bson:"total"`
         Data  []Data  `bson:"data"`
      }
      
      var new = Demo{
         Total: []Total{
            {
               Count: 100,
            },
         },
         Data: []Data{
            {
               "Alice",
            },
         },
      }
      
      type receiver struct {
         Total interface{}
         Data  interface{}
      }
      
      func TestUnmarshalBson(t *testing.T) {
         // a,b not get the value I want
         a := make([]Total, 0)
         b := make([]Data, 0)
         recv := receiver{
            Total: &a,
            Data:  &b,
         }
      }
      
      

            Assignee:
            qingyang.hu@mongodb.com Qingyang Hu
            Reporter:
            wangyuhengs@outlook.com C1tas Wcniwohcrf
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: