jinzhu / copier

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

source with nil pointer replacing existing pointer in destination #167

Open iDevoid opened 2 years ago

iDevoid commented 2 years ago

Reproducible Example

go playground

Description

expectation

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

kcchu commented 2 years ago

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.