diff --git a/bind.go b/bind.go index 507def3ea..8cb352b35 100644 --- a/bind.go +++ b/bind.go @@ -159,6 +159,12 @@ func (b *DefaultBinder) bindData(destination interface{}, data map[string][]stri for k, v := range data { if isElemString { val.SetMapIndex(reflect.ValueOf(k), reflect.ValueOf(v[0])) + } else if isElemInterface { + if len(v) == 1 { + val.SetMapIndex(reflect.ValueOf(k), reflect.ValueOf(v[0])) + } else { + val.SetMapIndex(reflect.ValueOf(k), reflect.ValueOf(v)) + } } else { val.SetMapIndex(reflect.ValueOf(k), reflect.ValueOf(v)) } diff --git a/bind_test.go b/bind_test.go index db7693cb9..5051262f8 100644 --- a/bind_test.go +++ b/bind_test.go @@ -498,7 +498,7 @@ func TestDefaultBinder_bindDataToMap(t *testing.T) { assert.Equal(t, map[string]interface{}{ "multiple": []string{"1", "2"}, - "single": []string{"3"}, + "single": "3", }, dest, ) @@ -510,7 +510,7 @@ func TestDefaultBinder_bindDataToMap(t *testing.T) { assert.Equal(t, map[string]interface{}{ "multiple": []string{"1", "2"}, - "single": []string{"3"}, + "single": "3", }, dest, )