Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-12588] JSONEncoder's sortedKeys doesn't work when Key is an enum that conforms to String #3258

Open
ankitspd opened this issue Apr 15, 2020 · 1 comment

Comments

@ankitspd
Copy link
Member

Previous ID SR-12588
Radar rdar://problem/62202368
Original Reporter @aciidb0mb3r
Type Bug
Additional Detail from JIRA
Votes 1
Component/s Compiler, Foundation
Labels Bug
Assignee None
Priority Medium

md5: f44fa76a09602e1ef66b339697c43ca2

Issue Description:

The following code produces different output on each invocation.

import Foundation

enum Key: String, Codable {
    case a, b, c
}

struct MyStruct: Encodable {
    var foo: [Key: Int]
}

let t = MyStruct(foo: [
    .a: 1,
    .b: 1,
    .c: 1,
])

let encoder = JSONEncoder()
encoder.outputFormatting = [.sortedKeys, .prettyPrinted]
let encoded = try encoder.encode(t)
print(String(data: encoded, encoding: .utf8)!)
@beccadax
Copy link
Contributor

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants