You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
When the target map to decode the result to is strongly typed, the decoding process fails, even if the map type matches the source structure.
func TestDecode_structToTypedMap(t *testing.T) {
type SourceChild struct {
String string `mapstructure:"string"`
}
type SourceParent struct {
Child SourceChild `mapstructure:"child"`
}
var target map[string]map[string]interface{} // This is the reason the test fails
//var target map[string]interface{} // With this variant it works
source := SourceParent{
Child: SourceChild{
String: "hello",
},
}
if err := Decode(source, &target); err != nil {
t.Fatalf("got error: %s", err)
}
expected := map[string]interface{}{
"child": map[string]interface{}{
"string": "hello",
},
}
if !reflect.DeepEqual(target, expected) {
t.Fatalf("bad: \nexpected: %#v\nresult: %#v", expected, target)
}
}
Produces:
=== RUN TestDecode_structToTypedMap
mapstructure_test.go:2884: got error: cannot assign type 'mapstructure.SourceChild' to map value field of type 'map[string]interface {}'
--- FAIL: TestDecode_structToTypedMap (0.00s)
As the target sutructure matches the needs of the decoding process, I would expect this to work.
mapstructure version bf980b3
go version go1.18.7 linux/amd64
The text was updated successfully, but these errors were encountered:
When the target map to decode the result to is strongly typed, the decoding process fails, even if the map type matches the source structure.
Produces:
As the target sutructure matches the needs of the decoding process, I would expect this to work.
mapstructure version bf980b3
go version go1.18.7 linux/amd64
The text was updated successfully, but these errors were encountered: