Skip to content

Commit

Permalink
🐞 fix: Fixes the issue with null checks for pointer type fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sohaha committed Jul 16, 2024
1 parent b1d7c38 commit 97226bf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ztype/conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func (d *Conver) toMapFromStruct(name string, dataVal reflect.Value, val reflect
return fmt.Errorf("cannot assign type '%s' to map value field of type '%s'", vTyp, valMap.Type().Elem())
}

if vTyp.Kind() == reflect.Pointer {
if vTyp.Kind() == reflect.Pointer && !v.IsZero() {
vTyp = v.Elem().Type()
}

Expand Down
3 changes: 3 additions & 0 deletions ztype/to_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,12 @@ func TestConv(t *testing.T) {
Tags []string
Options map[string]string
Name *string
Name2 string
Name3 *string
Nick string
Date *_time `json:"d"`
Day ztime.LocalTime
Day2 *time.Time
}{
Name: &name,
Nick: name,
Expand Down

0 comments on commit 97226bf

Please sign in to comment.