Closed alextr98 closed 2 years ago
The cause of this is because the Go struct tag is an incorrect syntax.
Tags are supposed to be space separated, not semi-colon separated. As a result, the reflect package is unable to parse the next record.
(~/x) % go vet
# x.y.z
./t.go:11:2: struct field tag `json:",omitempty" ; gorm:"size:4"` not compatible with reflect.StructTag.Get: bad syntax for struct tag pair
./t.go:12:2: struct field tag `gorm:"size:4" ; json:",omitempty"` not compatible with reflect.StructTag.Get: bad syntax for struct tag pair
As per @dsnet's comment, closing as not a bug.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
$ go envWhat did you do?
package main
import ( "encoding/json" "fmt" "gorm.io/gorm" )
type Test struct { gorm.Model `json:"-"` JsonFirst string `json:",omitempty" ; gorm:"size:4"` GormFirst string `gorm:"size:4" ; json:",omitempty"` }
func main() { var t1 Test s1,_ := json.Marshal(t1) fmt.Println(string(s1))
}
What did you expect to see?
{}
What did you see instead?
{"GormFirst":""}