go-yaml / yaml

YAML support for the Go language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[feature] extended Marshaler interface with passing extra parameters

metux opened this issue · comments

There are cases where objects could be marshaled in different ways,.especially those with custom marshalers.

Example: i've got an recursive dictionary with extra features like defaults and variable substitution. Depending on the actual use case, marshaling could be done eg w/ or w/o merging defaults, or w/ or w/o resolving variables.

Adding new frontend functions with extra parameters (eg. yaml.MarshalExt(...)) simple. But the Marshaler interface has no means for passing extra parameters down to the individual object.

Proposal: extended Marshaler interface, eg.

type MarshalerExr interface {
MarshalYAMLExt(args map[string] string) (interface{}, error)
}

Of course there yet needs to be some convention on naming these args keys, in order to prevent clashes between different object types.