Skip to content

Commit

Permalink
Use sortedKeys option for JSON encoder (#1219)
Browse files Browse the repository at this point in the history
  • Loading branch information
plu authored Nov 9, 2023
1 parent 56661dc commit a69e548
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Templates/CodableContextTests/CodableContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CodableContextTests: QuickSpec {
#if canImport(ObjectiveC)
let encoder: JSONEncoder = {
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
return encoder
}()

Expand All @@ -22,14 +22,13 @@ class CodableContextTests: QuickSpec {
let value = AssociatedValuesEnum.someCase(id: 0, name: "a")

let encoded = try! encoder.encode(value)
expect(String(data: encoded, encoding: .utf8)).to(equal(
"""
{
"type" : "someCase",
"id" : 0,
"name" : "a"
}
"""
expect(String(data: encoded, encoding: .utf8)).to(equal("""
{
"id" : 0,
"name" : "a",
"type" : "someCase"
}
"""
))

let decoded = try! decoder.decode(AssociatedValuesEnum.self, from: encoded)
Expand Down

0 comments on commit a69e548

Please sign in to comment.