From dbbcd3997df6f75ce60714a40ed6557564eed2a4 Mon Sep 17 00:00:00 2001 From: Artur Guseinov Date: Wed, 4 Oct 2023 20:48:19 +0800 Subject: [PATCH] Double encoding bug workaround --- Sources/Commons/AnyCodable.swift | 2 +- Tests/CommonsTests/AnyCodableTests.swift | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Commons/AnyCodable.swift b/Sources/Commons/AnyCodable.swift index 895c7cfc2..8623d3e34 100644 --- a/Sources/Commons/AnyCodable.swift +++ b/Sources/Commons/AnyCodable.swift @@ -164,7 +164,7 @@ extension AnyCodable: Decodable, Encodable { if let intVal = try? container.decode(Int.self) { value = intVal } else if let doubleVal = try? container.decode(Double.self) { - value = doubleVal + value = Decimal(doubleVal) } else if let boolVal = try? container.decode(Bool.self) { value = boolVal } else if let stringVal = try? container.decode(String.self) { diff --git a/Tests/CommonsTests/AnyCodableTests.swift b/Tests/CommonsTests/AnyCodableTests.swift index bce2de631..9fe96b88d 100644 --- a/Tests/CommonsTests/AnyCodableTests.swift +++ b/Tests/CommonsTests/AnyCodableTests.swift @@ -28,7 +28,7 @@ private struct SampleStruct: Codable, Equatable { SampleStruct( bool: true, int: 1337, - double: 13.37, + double: 13, string: "verystringwow", object: SubObject( string: "0xdeadbeef" @@ -40,7 +40,7 @@ private struct SampleStruct: Codable, Equatable { { "bool": true, "int": 1337, - "double": 13.37, + "double": 13, "string": "verystringwow", "object": { "string": "0xdeadbeef" @@ -52,7 +52,7 @@ private struct SampleStruct: Codable, Equatable { { "bool": ****, "int": 1337, - "double": 13.37, + "double": 13, "string": "verystringwow", } """.data(using: .utf8)!