Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode both empty and nil slices into [] #81

Merged
merged 1 commit into from
Feb 14, 2020
Merged

Encode both empty and nil slices into [] #81

merged 1 commit into from
Feb 14, 2020

Conversation

k1LoW
Copy link
Sponsor Contributor

@k1LoW k1LoW commented Feb 14, 2020

link: #80

Encode both empty and nil slices into []

package main

import (
	"fmt"
	"github.com/goccy/go-yaml"
)

func main() {
	tests := []struct {
		value interface{}
	}{
		{
			value: struct {
				A []string `yaml:"a"`
			}{
				A: []string(nil),
			},
		},
		{
			value: struct {
				A []string `yaml:"a"`
			}{
				A: []string{},
			},
		},
	}
	
	for _, tt := range tests {
		d, _ := yaml.Marshal(tt.value)
		fmt.Printf("%s", string(d))
	}
}

before:

a:
a:

after:

a: []
a: []

@goccy
Copy link
Owner

goccy commented Feb 14, 2020

LGTM !!

@goccy goccy merged commit fee8ac5 into goccy:master Feb 14, 2020
@k1LoW k1LoW deleted the empty-slice-and-nil-slice2 branch February 14, 2020 10:02
@k1LoW k1LoW mentioned this pull request Mar 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants