Skip to content

Commit 9622474

Browse files
committed
bind: Maintain backwards compatibility for map[string]interface{} binding
1 parent f7d9f51 commit 9622474

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

bind.go

+6
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ func (b *DefaultBinder) bindData(destination interface{}, data map[string][]stri
159159
for k, v := range data {
160160
if isElemString {
161161
val.SetMapIndex(reflect.ValueOf(k), reflect.ValueOf(v[0]))
162+
} else if isElemInterface {
163+
if len(v) == 1 {
164+
val.SetMapIndex(reflect.ValueOf(k), reflect.ValueOf(v[0]))
165+
} else {
166+
val.SetMapIndex(reflect.ValueOf(k), reflect.ValueOf(v))
167+
}
162168
} else {
163169
val.SetMapIndex(reflect.ValueOf(k), reflect.ValueOf(v))
164170
}

bind_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ func TestDefaultBinder_bindDataToMap(t *testing.T) {
498498
assert.Equal(t,
499499
map[string]interface{}{
500500
"multiple": []string{"1", "2"},
501-
"single": []string{"3"},
501+
"single": "3",
502502
},
503503
dest,
504504
)
@@ -510,7 +510,7 @@ func TestDefaultBinder_bindDataToMap(t *testing.T) {
510510
assert.Equal(t,
511511
map[string]interface{}{
512512
"multiple": []string{"1", "2"},
513-
"single": []string{"3"},
513+
"single": "3",
514514
},
515515
dest,
516516
)

0 commit comments

Comments
 (0)