diff --git a/private/protocol/json/jsonutil/unmarshal.go b/private/protocol/json/jsonutil/unmarshal.go index f9334879b80..481acfa124e 100644 --- a/private/protocol/json/jsonutil/unmarshal.go +++ b/private/protocol/json/jsonutil/unmarshal.go @@ -9,6 +9,7 @@ import ( "math" "math/big" "reflect" + "strconv" "strings" "time" @@ -259,6 +260,16 @@ func (u unmarshaler) unmarshalScalar(value reflect.Value, data interface{}, tag return err } value.Set(reflect.ValueOf(v)) + case *int64: + v, err := strconv.ParseInt(d, 10, 64) + if err != nil { + fp, err := strconv.ParseFloat(d, 64) + if err != nil { + return fmt.Errorf("failed converting string that should contain a number to int64 %s: %w", d, err) + } + v = int64(fp) + } + value.Set(reflect.ValueOf(aws.Int64(v))) case *float64: // These are regular strings when parsed by encoding/json's unmarshaler. switch { diff --git a/private/protocol/json/jsonutil/unmarshal_test.go b/private/protocol/json/jsonutil/unmarshal_test.go index 1e7ec3615ef..235a230a31d 100644 --- a/private/protocol/json/jsonutil/unmarshal_test.go +++ b/private/protocol/json/jsonutil/unmarshal_test.go @@ -102,6 +102,18 @@ func TestUnmarshalJSON_JSONNumber(t *testing.T) { IntField: aws.Int64(123456789), }, }, + "integer field as string": { + JSON: `{"intField":"123456789"}`, + Expected: input{ + IntField: aws.Int64(123456789), + }, + }, + "integer field as string truncated": { + JSON: `{"intField":"123456789.123"}`, + Expected: input{ + IntField: aws.Int64(123456789), + }, + }, "float64 field": { JSON: `{"floatField":123456789.123}`, Expected: input{