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 with and without pointers #714

Open
vanbroup opened this issue Mar 22, 2021 · 2 comments
Open

MarshalYAML interface with and without pointers #714

vanbroup opened this issue Mar 22, 2021 · 2 comments

Comments

@vanbroup
Copy link

MarshalYAML doesn't seem to have the same behaviour as MarshalJSON, for example when the interface is implemented on an interface:

In encoding/json the MarshalJSON interface implemented as (d *Data) MarshalJSON() triggers on pointers and non-pointers:
https://play.golang.org/p/LFoqw1VHz8l

Doing the same with (d *Data) MarshalYAML(), doesn't work:
https://play.golang.org/p/hFnuiLpKq73

But when removing the pointer to (d Data) MarshalYAML() or by changing the data to pointers, it works fine:
https://play.golang.org/p/FyngGj0lATf

@cyberbeast
Copy link

Any comments on this? This is a very subtle departure from MarshalJSON() but one with high impact. I've encountered this behavior in a project recently and it was hard to reconcile findings because it doesn't work the same way as MarshalJSON(), and there is no explicit documentation regarding the usage of the Marshaler interface to document this either.

@aathan
Copy link

aathan commented Aug 9, 2023

#979

masonkatz added a commit to SoftIron/yaml that referenced this issue Aug 24, 2023
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

3 participants