copier icon indicating copy to clipboard operation
copier copied to clipboard

source with nil pointer replacing existing pointer in destination

Open iDevoid opened this issue 3 years ago • 1 comments

Reproducible Example

go playground

Description

expectation

Should not replace non-nil pointer with nil or non existing data

iDevoid avatar Sep 21 '22 05:09 iDevoid

This is the line of code that lead to this behavior: https://github.com/jinzhu/copier/blob/0e264e93b8f4334ee24e3d8811e3f76c50734258/copier.go#L462-L467

But it seems to me that it is that intended behavior because a nil is also a value that should be copied as if other values. Setting IgnoreEmpty in copier.Option could achieve what you want. However, not only it would ignore nil pointers in source, but also ignore zero values such as empty strings.

kcchu avatar Sep 25 '22 13:09 kcchu