You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"github.com/globalsign/mgo/bson""fmt""encoding/json"
)
typeT1struct {
Foochanstring`json:"-",bson:"-"`
}
typeT2struct {
Barchanstring`bson:"-",json:"-"`
}
typeT3struct {
Foochanstring`bson:"-"`
}
typeT4struct {
Barchanstring`json:"-"`
}
funcmain() {
_, err:=bson.Marshal(&T1{Foo: make(chanstring, 0)})
iferr!=nil {
fmt.Printf("json and bson fails due to multiple ignored tags: %s\n", err)
}
_, err=json.Marshal(&T2{Bar: make(chanstring, 0)})
iferr!=nil {
fmt.Printf("bson and json fails due to multiple ignored tags: %s\n", err)
}
_, err=bson.Marshal(&T3{Foo: make(chanstring, 0)})
iferr==nil {
fmt.Println("bson passes due to one ignore tag.")
}
_, err=json.Marshal(&T4{Bar: make(chanstring, 0)})
iferr==nil {
fmt.Println("json passes due to one ignore tag.")
}
}
What did you expect to see?
All four use cases should work. Struct field tags denoted by "-" should be ignored by all marshallers.
What did you see instead?
json and bson fails due to multiple ignored tags: Can't marshal chan string in a BSON document
bson and json fails due to multiple ignored tags: json: unsupported type: chan string
bson passes due to one ignore tag.
json passes due to one ignore tag.
My use case is having types pull double-duty as both MongoDB objects as well as JSON objects, but I want to be able to ignore unsupported types, such as channels, with struct tags and have both struct tags be ignored properly.
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes. I can replicate this with
go1.10.3 linux/amd64
andgo1.10.2 windows/amd64
.What operating system and processor architecture are you using (
go env
)?What did you do?
What did you expect to see?
All four use cases should work. Struct field tags denoted by
"-"
should be ignored by all marshallers.What did you see instead?
My use case is having types pull double-duty as both MongoDB objects as well as JSON objects, but I want to be able to ignore unsupported types, such as channels, with struct tags and have both struct tags be ignored properly.
The text was updated successfully, but these errors were encountered: