Closed xtutu closed 2 years ago
for example
package mongo_test_test import ( "encoding/json" "fmt" "github.com/globalsign/mgo/bson" "math" "testing" ) func Stringify(o interface{}) string { data, err := json.Marshal(o) if err != nil { return err.Error() } return string(data) } type Data struct { Type int32 `bson:"Type"` Data map[uint64]string `bson:"Data"` } func TestBsonMap(t *testing.T) { mapData := make(map[uint64]string) numInt64 := uint64(math.MaxUint64) mapData[numInt64] = "a" data := &Data{ Type: 100, Data: mapData, } byteData, err := bson.Marshal(data) if err != nil { fmt.Println(err) } var after = &Data{} err = bson.Unmarshal(byteData, after) fmt.Printf("%d\n", numInt64) fmt.Printf("%s\n", Stringify(after)) }
// the output should be: // 18446744073709551615 // {"Type":100,"Data":{"18446744073709551615":"a"}} // but got: // 18446744073709551615 // {"Type":100,"Data":{"9223372036854775808":"a"}}
for example