Decoding to maps with multiple indirection results in an error

Author: sagikazarmarkCreated Dec 8, 2023Updated Dec 8, 2023

As the title says, when trying to decode a pointer of a pointer of any supported type to a map, mapstructure returns an error saying '' expected a map, got 'ptr'.

The following code reproduces the issue on the latest main branch:

go
	type Struct struct {
		Foo string
	}

	s := &Struct{
		Foo: "bar",
	}

	ss := &s
	sss := &ss

	var m map[string]interface{}

	if err := Decode(sss, &m); err != nil {
		panic(err)
	}

The relevant code (here) checks for one level of indirection.

See https://github.com/spf13/viper/issues/1706 for more details