jinzhu / copier

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

[Bug] Copying pointer to struct is not working #77

Closed maeglindeveloper closed 3 years ago

maeglindeveloper commented 3 years ago

Reproducible Example

https://play.golang.org/p/dGhNPDZQtPu

Description

Hi everyone,

I had several issue copying a structure to another which contain pointers.

It seems that if your structure cointain some pointer to another struct, the pointer address from the source is copied rather than building a new object and set the value of the pointer to the new instance.

So when you change the value of the destination object for instance, you will automatically change the value of the source ... which is not what I / (we ?) expect.

I shared the example here I think that is a huge issue

Thanks in advance :) !

@jinzhu

maeglindeveloper commented 3 years ago

EDIT: I upgraded to v0.2.4 and it has the option DeepCopy. Using the CopyWithOptions does the job ! :) Thanks.

Still have another issue but I will open another ticket. Thanks