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 struct #355

Open dennis-dko opened 7 months ago

dennis-dko commented 7 months ago

Hello,

I want to decode the values from a struct to another struct, it works for all primitive datatypes but not for custom types like the Foobar example which uses the World struct as new custom type for Hello.

type World struct {
    time.Time
} 

type Foobar struct {
    Hello World 
} 

type Dest struct {
  CurrentTime World `mapstructure:"Hello"`
} 

src := Foobar{
 Hello: time.Now(), 
} 

var dest Dest

mapstructure.Decode(src, &dest) 

I have the same problem with sql.NullString.

The problem is I have to decode the complete struct in the hook function and I hope I can do it easier.