goccy / go-yaml

YAML support for the Go language
MIT License
1.17k stars 131 forks source link

fix: skip encoding an inline field if it is null #386

Closed zoncoen closed 1 year ago

zoncoen commented 1 year ago

The current implementation returns an error if an inline field is null. This PR makes skipping encoding null inline fields.

This behavior is the same as encoding/json.

b, err := json.Marshal(struct {
    *base `yaml:",inline"`
    C     bool
}{
    C: true,
})
if err != nil {
    panic(err)
}
fmt.Println(string(b))

=> {"C":true}

codecov-commenter commented 1 year ago

Codecov Report

Merging #386 (d90e6f3) into master (42fb764) will increase coverage by 0.05%. The diff coverage is 100.00%.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #386 +/- ## ========================================== + Coverage 75.61% 75.66% +0.05% ========================================== Files 13 13 Lines 4650 4652 +2 ========================================== + Hits 3516 3520 +4 + Misses 874 873 -1 + Partials 260 259 -1 ```
goccy commented 1 year ago

Thank you for your great PR !! LGTM 👍