Skip to content

Commit

Permalink
Add sortedKeys for encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcmz committed Oct 25, 2023
1 parent 7b864b0 commit 5c1b88b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/Decode/FlowArgument+Decode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ extension Flow.Argument: FlowCodable {
}

private func modelToDict<T: Encodable>(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
Expand Down
11 changes: 11 additions & 0 deletions Sources/Flow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions Sources/Models/FlowArgument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5c1b88b

Please sign in to comment.