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

      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: