Skip to content

Commit

Permalink
Merge pull request #75 from AntonSkrub/struct-value-pointer
Browse files Browse the repository at this point in the history
Fixed pointer conversion in setStructField
  • Loading branch information
Valentin-Kaiser authored Jul 14, 2023
2 parents 7c249b0 + 484b802 commit 79ae4df
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions dbase/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ func setStructField(tags map[string]string, obj interface{}, name string, value
structFieldType := structFieldValue.Type()
value = dynamicCast(value, structFieldType)
val := reflect.ValueOf(value)

if structFieldType.Kind() == reflect.Ptr {
// Convert the value to a pointer to match the field type
ptr := reflect.New(structFieldType.Elem())
ptr.Elem().Set(val)
val = ptr
}

if structFieldType != val.Type() {
return newError("dbase-conversion-setstructfield-2", fmt.Errorf("provided value type %v didn't match obj field type %v", val.Type(), structFieldType))
}
Expand Down

0 comments on commit 79ae4df

Please sign in to comment.