jinzhu / copier

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

fix json error when struct field is byte slice and is nil #143

Open hemanth132 opened 2 years ago

hemanth132 commented 2 years ago

Reproducible Example

Added a testcase and the code fix for the same here: https://github.com/jinzhu/copier/pull/142

Description

When using copier for a struct with a nil byte slice as a field to a target struct which contains a similar nil byte slice field, the target slice field is being set with an empty slice instead of nil.

This cause issues, when the resulting target slice is converted to json using json.Marsha() method. Added a testcase for the same.