mitchellh / mapstructure

Go library for decoding generic map values into native Go structures and vice versa.
https://gist.github.com/mitchellh/90029601268e59a29e64e55bab1c5bdc
MIT License
7.93k stars 677 forks source link

Decoding Struct to Map with Embedded pointer to Struct #353

Open dima-koniaiev-solid opened 8 months ago

dima-koniaiev-solid commented 8 months ago

Hey, everyone! I still can reproduce the problem with decoding the embedded pointer from this issue. Here is the code to reproduce the problem:

Expected result: map[B:map[Name:]] Actual result: map[B:0x14000132000]

package main

import (
    "github.com/mitchellh/mapstructure"
    "log"
)

func main() {
    testMap := make(map[string]interface{})
    a := A{&B{}}
    err := mapstructure.Decode(a, &testMap)

    if err != nil {
        panic(err)
    }

    log.Println(testMap)
}

type A struct {
    B *B
}

type B struct {
    Name string
}

If you update this B struct to the following one everything works as expected:

type B struct {
    Test string `mapstructure:",omitempty"`
    Name string
}