mirror of
https://github.com/goccy/go-yaml.git
synced 2025-12-08 06:09:57 +00:00
chore: clarify omitempty behaviour. (#696)
Fixes 0-1 steps from https://github.com/goccy/go-yaml/issues/695. Signed-off-by: bwplotka <bwplotka@gmail.com>
This commit is contained in:
parent
ee37df774b
commit
d1e3460292
2 changed files with 16 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"net/netip"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -561,6 +562,18 @@ func TestEncoder(t *testing.T) {
|
|||
},
|
||||
nil,
|
||||
},
|
||||
// Highlighting differences of go-yaml omitempty vs std encoding/json
|
||||
// omitempty. Encoding/json will emit the following fields: https://go.dev/play/p/VvNpdM0GD4d
|
||||
{
|
||||
"{}\n",
|
||||
struct {
|
||||
// This type has a custom IsZero method.
|
||||
A netip.Addr `yaml:"a,omitempty"`
|
||||
B struct{ X, y int } `yaml:"b,omitempty"`
|
||||
}{},
|
||||
nil,
|
||||
},
|
||||
|
||||
// OmitEmpty global option.
|
||||
{
|
||||
"a: 1\n",
|
||||
|
|
|
|||
3
yaml.go
3
yaml.go
|
|
@ -108,6 +108,9 @@ func (s MapSlice) ToMap() map[interface{}]interface{} {
|
|||
// fields are zero, unless they implement an IsZero
|
||||
// method (see the IsZeroer interface type), in which
|
||||
// case the field will be included if that method returns true.
|
||||
// Note that this definition is slightly different from the Go's
|
||||
// encoding/json 'omitempty' definition. It combines some elements
|
||||
// of 'omitempty' and 'omitzero'. See https://github.com/goccy/go-yaml/issues/695.
|
||||
//
|
||||
// flow Marshal using a flow style (useful for structs,
|
||||
// sequences and maps).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue