[GODRIVER-1188] bson struct field interface Marshal, Unmarshal value not equal Created: 04/Jul/19  Updated: 16/Nov/21  Resolved: 07/Aug/20

Status: Closed
Project: Go Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Tiansheng Ren Assignee: Isabella Siu (Inactive)
Resolution: Done Votes: 0
Labels: mgocompat
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File image-2019-07-04-16-35-34-142.png    

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



 Comments   
Comment by Isabella Siu (Inactive) [ 07/Aug/20 ]

The results will match if you use mgocompatRegistry to marshal and unmarshal.

Comment by Tiansheng Ren [ 04/Jul/19 ]

Generated at Thu Feb 08 08:35:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.