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.

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • 2.0.0
    • 1.4.4
    • BSON
    • None
    • go 1.15.6
    • Major Change

    Description

      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,
         }
      }
      
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            wangyuhengs@outlook.com C1tas Wcniwohcrf
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated: