You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
MarshalYAML
doesn't seem to have the same behaviour asMarshalJSON
, for example when the interface is implemented on an interface:In
encoding/json
theMarshalJSON
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
The text was updated successfully, but these errors were encountered: