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

bson struct field interface Marshal, Unmarshal value not equal

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • BSON

    Description

      // code placeholder
       
       
       
      import (
          "testing"
       
       
          "github.com/mongodb/mongo-go-driver/bson"
          "github.com/stretchr/testify/require"
      )
       
      func TestStructBson(t *testing.T) {
          type ts struct {
              Value interface{}
          }
       
          valMap := map[string]interface{}\{"a": 1}
          instance := ts\{Value: valMap}
       
          instanceByte, err := bson.Marshal(instance)
          require.NoError(t, err)
       
          var newInstance ts
          err = bson.Unmarshal(instanceByte, &newInstance)
          require.NoError(t, err)
       
          var i interface{}
          err = bson.Unmarshal(instanceByte, &i)
          require.NoError(t, err)
       
          t.Errorf("%v %v", instance.Value, newInstance.Value)
      }
      

      Attachments

        Activity

          People

            isabella.siu@mongodb.com Isabella Siu (Inactive)
            reage521@gmail.com Tiansheng Ren
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: