-
-
Notifications
You must be signed in to change notification settings - Fork 203
Description
Describe the bug
As discussed on the global omitempty option PR, we noticed go-yaml is implementing omitemptyin a different way than Go std encoding/json which may cause some surprises. Initially we thought omitempty is implemented as omitzero, but in fact go-yaml omitempty is a mix of features from std encoding omitempty and omitzero features (:
Technically, those those two are a distinct separate options e.g. in encoding/json with omitzero being introduced only recently to the std json lib..
The difference is a bit nuanced, but the key difference can be distilled into two main things:
omitzeroshould not omit[]int{},omitemptyshould. go-yaml works well here, just do not implement omitzero.omitemptyshould not treat nested structs zero value as empty, but go-yaml doesomitzeroshould checkIsZero() boolinterface,omitemptynot.
This "bug" is often a feature, because generally what user wants is something close to omitzero. Perhaps this is why gopkg.in/v2 implemented omitempty as such and go-yaml simply took that.
Thoughts? @goccy
Version Variables
- Go version: 1.24
- go-yaml's Version: all until now 1.17.1