jinzhu / copier

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

How to copy from one data type to another data type with same name? #34

Closed kumarsiva07 closed 1 year ago

kumarsiva07 commented 6 years ago
// Model
type User struct {
    JoinedAt   time.Time
    ReleavedAt *time.Time
}

// Resource
type UserResource struct {
    JoinedAt   string
    ReceivedAt string
}

Want to copy from User to UserResource.

daluu commented 6 years ago

I wonder if that's possible (at the moment), as it would require casting the data types in the copy process.

ilius commented 5 years ago

Can you cast time.Time to string? You need to specify the format somehow (unless it's JSON-specific)

tomdevelops commented 3 years ago

hey, i know i'm a little bit late for the party 😅, but i made a PR #115 to make these kind of type conversions via a converter option. Have a look into the PR for an example, should be simliar to yours. cheers tom

uded commented 1 year ago

Closing as it is addressed via #115