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

bson struct field interface Marshal, Unmarshal value not equal

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • Labels:

      // 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)
      }
      

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

              Created:
              Updated:
              Resolved: