jinzhu / copier

Copier for golang, copy value from struct to struct and more
MIT License
5.57k stars 489 forks source link

Unexported copy of struct is failing #202

Open mahadeva1989 opened 1 year ago

mahadeva1989 commented 1 year ago

I have a situation where I'm not able to copy unexported struct type values to the exported base fields.

package main

import ( "fmt"

"github.com/jinzhu/copier"

)

func main() { type common struct { Common1 int json:"Common1" Common2 string json:"Common2" }

type source struct {
    Name        string `json:"Name"`
    Description string `json:"Description"`
    common
}

type destination struct {
    Name        string `json:"Name"`
    Description string `json:"Description"`
    Common1     int    `json:"Common1"`
    Common2     string `json:"Common2"`
}

src := source{Name: "name", Description: "description", common: common{Common1: 2, Common2: "common2"}}
dest := destination{}
copier.Copy(&dest, src)
fmt.Printf("values %v", dest)

}

Actual : values {name description 0 }

Expected Please advise me on how to get the output as values {name description 2 common2}