Closed
Description
The behavior of JSONEncoder.OutputFormatting.sortedKeys
differs between the Darwin and non-Darwin implementation of Foundation.
A developer may rely on this formatting option to make a test deterministic. However, because the behavior differs across platforms, the test is not portable.
Test Case
import Foundation
let dictionary = [
"a": "a",
"B": "b"
]
let jsonEncoder = JSONEncoder()
jsonEncoder.outputFormatting = [.sortedKeys]
let jsonBytes = try! jsonEncoder.encode(dictionary)
let jsonString = String(decoding: jsonBytes, as: UTF8.self)
print(jsonString)
Darwin Output
{"a":"a","B":"b"}
Non-Darwin Output
{"B":"b","a":"a"}
Metadata
Metadata
Assignees
Labels
No labels