mapstructure icon indicating copy to clipboard operation
mapstructure copied to clipboard

Slice or Map not decoded

Open DasJott opened this issue 3 years ago • 3 comments

If a field is a slice of structs they are not decoded, instead it stays a slice of that type.
Same goes for maps.

See example here.

DasJott avatar May 18 '21 07:05 DasJott

Hm yes, this is intended and I think would be a breaking change to change the default. By decoding to a map[string]interface{} you are saying that the value interface{} is anything that can be assigned to it. mapstructure realizes that it can decode directly onto there, which I think is arguably correct.

I'd be open to an enhancement that introduces a new option to "prefer maps" basically in this scenario.

mitchellh avatar Apr 20 '22 22:04 mitchellh

#314 looks like a perfect fix for this and much wanted :)

dangra avatar Feb 12 '23 23:02 dangra

Given that this project is being officially forked to https://github.com/go-viper/mapstructure (see https://github.com/mitchellh/mapstructure/issues/349) I'd suggest that this issue (and associated PR) be opened against that project now.

jchunkins avatar Jun 19 '24 21:06 jchunkins