Skip to content

Commit

Permalink
Fix resolving ptr while decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
roeldev committed Apr 30, 2024
1 parent 5d45964 commit eef065a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,14 @@ func (u *Unmarshaler) unmarshal(v Value, dest reflect.Value, nested bool) error

var err error
for dest.Kind() == reflect.Ptr {
// take the value dest points to and make sure it is not nil
if dest, err = value(dest.Elem()); err != nil {
return err
if dest.IsNil() {
if !dest.CanSet() {
return errors.New(ErrUnableToSet)
}

dest.Set(reflect.New(dest.Type().Elem()))
}
dest = dest.Elem()
}

// handle aliases of primitive types
Expand Down

0 comments on commit eef065a

Please sign in to comment.