Fix reflectutils.Convert() for maps and []any

This commit is contained in:
Arsen Musayelyan 2022-06-02 02:09:47 -07:00
parent e518b68d8c
commit 6ee3602128
1 changed files with 3 additions and 1 deletions

View File

@ -104,12 +104,14 @@ func Convert(in reflect.Value, toType reflect.Type) (reflect.Value, error) {
err := mapstructure.Decode(in.Interface(), to.Addr().Interface())
if err == nil {
return to, nil
} else {
return reflect.Value{}, err
}
}
// If input is a slice of any, and output is an array or slice
if in.Type() == reflect.TypeOf([]any{}) &&
to.Kind() == reflect.Slice || to.Kind() == reflect.Array {
(to.Kind() == reflect.Slice || to.Kind() == reflect.Array) {
// Use ConvertSlice to convert value
return reflect.ValueOf(ConvertSlice(
in.Interface().([]any),