mapstructure icon indicating copy to clipboard operation
mapstructure copied to clipboard

Decoding to maps with multiple indirection results in an error

Open sagikazarmark opened this issue 1 year ago • 0 comments

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:

	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

sagikazarmark avatar Dec 08 '23 22:12 sagikazarmark