diff --git a/Sources/AWSSDKSwiftCore/Decoder/DictionaryDecoder.swift b/Sources/AWSSDKSwiftCore/Decoder/DictionaryDecoder.swift index 930b3c4d1..22dd9d123 100644 --- a/Sources/AWSSDKSwiftCore/Decoder/DictionaryDecoder.swift +++ b/Sources/AWSSDKSwiftCore/Decoder/DictionaryDecoder.swift @@ -1115,17 +1115,25 @@ extension _DictionaryDecoder { return Float(number) } + if let number = value as? Int { + return Float(number) + } + throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value) } fileprivate func unbox(_ value: Any, as type: Double.Type) throws -> Double? { guard !(value is NSNull) else { return nil } - guard let number = value as? Double else { - throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value) + if let number = value as? Double { + return number } - return number + if let number = value as? Int { + return Double(number) + } + + throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value) } fileprivate func unbox(_ value: Any, as type: String.Type) throws -> String? { diff --git a/Tests/AWSSDKSwiftCoreTests/DictionaryDecoderTests.swift b/Tests/AWSSDKSwiftCoreTests/DictionaryDecoderTests.swift index 7d82af113..114108592 100644 --- a/Tests/AWSSDKSwiftCoreTests/DictionaryDecoderTests.swift +++ b/Tests/AWSSDKSwiftCoreTests/DictionaryDecoderTests.swift @@ -50,8 +50,8 @@ class DictionaryDecoderTests: XCTestCase { "uint16": UInt16.max, "uint32": UInt32.max, "uint64": UInt64.max, - "double": 2.0, - "float": 3.0, + "double": Double.greatestFiniteMagnitude, + "float": Float.greatestFiniteMagnitude, "string": "hello", "data": "hello".data(using: .utf8)!, "bool": true, @@ -73,8 +73,8 @@ class DictionaryDecoderTests: XCTestCase { XCTAssertEqual(a.b.uint16, 65535) XCTAssertEqual(a.b.uint32, 4294967295) XCTAssertEqual(a.b.uint64, 18446744073709551615) - XCTAssertEqual(a.b.double, 2.0) - XCTAssertEqual(a.b.float, 3.0) + XCTAssertEqual(a.b.double, 1.7976931348623157E+308) + XCTAssertEqual(a.b.float, 3.40282347E+38) XCTAssertEqual(a.b.string, "hello") XCTAssertEqual(a.b.data, "hello".data(using: .utf8)) XCTAssertEqual(a.b.bool, true)