0

like

type User struct {
    ID       int32     `json:"_id"` 
    Week     string    `json:"week"`         
}

json.Marshal(&User{},true)//omitempty is true

will return

{}

is bson,yaml,sql or any other library support this feature?

curtank
  • 600
  • 2
  • 7
  • 18
  • No, but you can use a tool like `github.com/fatih/gomodifytags` to modify the types in your source code easily. – Dave C Aug 01 '19 at 12:30
  • the thing is that I accept an object, do some processing, and then hand the object to json,there is no way that I can edit the original struct. – curtank Aug 01 '19 at 12:48
  • You can copy the original type and then modify the tags. To guarantee compatibility if the original changes, add a type conversion from the original to your type somewhere. – Peter Aug 01 '19 at 15:21

0 Answers0