diff --git a/core/mapping/unmarshaler.go b/core/mapping/unmarshaler.go index b86ef8f46..56e588392 100644 --- a/core/mapping/unmarshaler.go +++ b/core/mapping/unmarshaler.go @@ -498,8 +498,15 @@ func (u *Unmarshaler) fillSlice(fieldType reflect.Type, value reflect.Value, map func (u *Unmarshaler) fillSliceFromString(fieldType reflect.Type, value reflect.Value, mapValue interface{}) error { var slice []interface{} - if err := jsonx.UnmarshalFromString(mapValue.(string), &slice); err != nil { - return err + switch v := mapValue.(type) { + case json.Number: + if err := jsonx.UnmarshalFromString(v.String(), &slice); err != nil { + return err + } + default: + if err := jsonx.UnmarshalFromString(mapValue.(string), &slice); err != nil { + return err + } } baseFieldType := Deref(fieldType.Elem()) diff --git a/core/mapping/unmarshaler_test.go b/core/mapping/unmarshaler_test.go index 0bf1739cc..f3b037f0e 100644 --- a/core/mapping/unmarshaler_test.go +++ b/core/mapping/unmarshaler_test.go @@ -2789,3 +2789,14 @@ func BenchmarkDefaultValue(b *testing.B) { } } } + +func TestUnmarshalJsonReaderArray(t *testing.T) { + payload := "{\"id\": 123}" + var res struct { + ID []string `json:"id"` + } + reader := strings.NewReader(payload) + err := UnmarshalJsonReader(reader, &res) + assert.Nil(t, err) + assert.Equal(t, 1, len(res.ID)) +}