Skip to content

Commit

Permalink
Handle structs as a fallback
Browse files Browse the repository at this point in the history
Otherwise types like time.Time get treated as a struct.
  • Loading branch information
ntnn committed Jan 16, 2024
1 parent 76a8da4 commit a40bb6f
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions value.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,6 @@ func (v Value) To(other any, opts ...ToOption) error {
return nil
}

// If the passed value is a pointer to a struct try
// converting Value to map and call .To
if target.Kind() == reflect.Struct {
m, err := v.Map()
if err != nil {
return err
}
return m.To(other, opts...)
}

var newValue any
var err error

Expand Down Expand Up @@ -142,6 +132,15 @@ func (v Value) To(other any, opts ...ToOption) error {
// case *[]byte:
// *typed = v.MustBytes()
default:
// If the passed value is a pointer to a struct try
// converting Value to map and call .To
if target.Kind() == reflect.Struct {
m, err := v.Map()
if err != nil {
return err
}
return m.To(other, opts...)
}
return fmt.Errorf("dataparse: unhandled type: %T", typed)
}
if err != nil {
Expand Down

0 comments on commit a40bb6f

Please sign in to comment.