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

MarshalYAML interface for struct and pointer both #357

Open
cloudzhou opened this issue Apr 11, 2018 · 1 comment
Open

MarshalYAML interface for struct and pointer both #357

cloudzhou opened this issue Apr 11, 2018 · 1 comment

Comments

@cloudzhou
Copy link

cloudzhou commented Apr 11, 2018

code:

type wrapint struct {
	i int
}
func (w *wrapint) MarshalYAML() (interface{}, error) {
	return w.i, nil
}

run yaml.Marshal() for
1) w := wrapint{i: 10} it will output "{}"
2) w := &wrapint{i: 10} it will output "10"

i think if it is necessary to output as "10" for both.

and if you make MarshalYAML to struct:

func (w wrapint) MarshalYAML() (interface{}, error) {
	return w.i, nil
}

both will output "10"

but for UnmarshalYAML,you sure need pointer as receiver in order to modify the value

@aathan
Copy link

aathan commented Aug 9, 2023

#979

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

No branches or pull requests

2 participants