I've been trying to write a custom UnmarshalYAML function that will unmarshal a yaml to a struct and also keep unexpected parameters saving them into a map into the struct itself.
I've tried writing this (https://go.dev/play/p/azf2hksriQ1) but, of course, I get an infinite loop when I try to unmarshal the struct inside the UnmarshalYAML.
Does anyone have any suggestion on how to make this work? Thank you very much!
You can use a simple wrapping technique where you define a type alias for your original type (so
yaml.Unmarshalerwon't call yourUmarshalYAMLmethod) and create a struct which embeds all known and unknown parameters.Playground Link