feat(config): support IgnoreZero option for config.Marhsaller (#153)

This commit is contained in:
mzz 2023-06-20 23:29:53 +08:00 committed by GitHub
parent 029849da5d
commit 6458ebd877
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,6 +38,7 @@ func (c *Config) Marshal(indentSpace int) (b []byte, err error) {
type Marshaller struct {
IndentSpace int
IgnoreZero bool
buf bytes.Buffer
}
@ -138,7 +139,7 @@ unsupported:
}
func (m *Marshaller) marshalLeaf(key string, from reflect.Value, depth int) (err error) {
if from.IsZero() {
if m.IgnoreZero && from.IsZero() {
// Do not marshal zero value.
return nil
}