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-15036] JSONEncoder sometimes encodes dictionaries as arrays #3206

Open
franklinsch opened this issue Aug 6, 2021 · 1 comment
Open

Comments

@franklinsch
Copy link
Member

Previous ID SR-15036
Radar rdar://81606906
Original Reporter @franklinsch
Type Bug
Environment

Ubuntu 18.04 using the toolchain swift-5.5-DEVELOPMENT-SNAPSHOT-2021-08-04-a-ubuntu18.04, which has:

Swift version 5.5-dev (LLVM 4afce2110750060, Swift 4ae44a5e0eac8a0)
Target: x86_64-unknown-linux-gnu

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 89b9b09cfba7115d37589ea5171b1014

Issue Description:

For the following program:

public struct DataAsset: Codable {
    public var sizes = [ImageSize: String]()
}

public struct ImageSize: Codable, Hashable {}

let data = try! JSONEncoder().encode(DataAsset(sizes: [ImageSize(): ""]))
print(String(data: data, encoding: .utf8)!)

The output I'm getting is `{"sizes":[{},""]}` on Linux (sizes should be a dictionary instead), which is unexpected. On macOS I'm getting `{"sizes": {}}`.

@YOCKOW
Copy link
Collaborator

YOCKOW commented Aug 15, 2021

Surprisingly, the behavior on Linux seems to be correct because of SR-7788.

EDIT: Swift 5.4.2 on macOS emits the same result with Linux.

@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