diff --git a/Sources/Decode/FlowArgument+Decode.swift b/Sources/Decode/FlowArgument+Decode.swift index 4d685df..863c9fe 100644 --- a/Sources/Decode/FlowArgument+Decode.swift +++ b/Sources/Decode/FlowArgument+Decode.swift @@ -230,7 +230,7 @@ extension Flow.Argument: FlowCodable { } private func modelToDict(result: T) -> [String: Any]? { - guard let data = try? JSONEncoder().encode(result), + guard let data = try? flow.encoder.encode(result), let model = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any] else { return nil diff --git a/Sources/Flow.swift b/Sources/Flow.swift index 6abe32c..963cbcc 100644 --- a/Sources/Flow.swift +++ b/Sources/Flow.swift @@ -38,6 +38,17 @@ public final class Flow { /// The access API client public private(set) var accessAPI: FlowAccessProtocol + internal var encoder: JSONEncoder { + let encoder = JSONEncoder() + encoder.outputFormatting = .sortedKeys + return encoder + } + + internal var decoder: JSONDecoder { + let decoder = JSONDecoder() + return decoder + } + /// Default access client will be HTTP Client init() { accessAPI = FlowHTTPAPI(chainID: chainID) diff --git a/Sources/Models/FlowArgument.swift b/Sources/Models/FlowArgument.swift index ce5c586..b0c2c75 100644 --- a/Sources/Models/FlowArgument.swift +++ b/Sources/Models/FlowArgument.swift @@ -35,8 +35,7 @@ public extension Flow { /// Encode argument into json data. public var jsonData: Data? { - let encoder = JSONEncoder() - guard let jsonData = try? encoder.encode(self) else { + guard let jsonData = try? flow.encoder.encode(self) else { return nil } return jsonData