mapstructure icon indicating copy to clipboard operation
mapstructure copied to clipboard

unsupported type for squash: interface

Open andig opened this issue 5 years ago • 2 comments

I would like to be able to build the target struct that decode maps into across different contributing pieces that are only stitched together at runtime. My approach for doing this is something like this where Bar extends a config stack by adding a Bar element around the wrapped config contained within:

type Wrapped interface{}

func (c *Bar) Stack(in interface{}) interface{} {
	out = struct {
		Wrapped `mapstructure:",squash"`
		Bar     string
	}{
		Wrapped: in,
	}
	return out
}

I'm using an anonymous interface as there is no anonymous struct. Unfortunately, mapstructure cannot decode squashed interfaces containing structs:

* Wrapped: unsupported type for squash: interface

Source code is there:

https://github.com/mitchellh/mapstructure/blob/5cc946fb764668e1e11b28b4fee49969c64aa8f6/mapstructure.go#L1221

Is that something that could be changed? Would be happy to look into a PR here.

andig avatar Apr 30 '20 07:04 andig

Yes this should be fixable, if you want to take a stab at it I'd appreciate it.

mitchellh avatar Apr 30 '20 15:04 mitchellh

@andig @mitchellh Created PR to add this functionality: #325

m1k1o avatar Apr 14 '23 21:04 m1k1o