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-7360] keyDecodingStrategy breaks dictionary-keys #4032

swift-ci opened this issue Apr 5, 2018 · 3 comments

[SR-7360] keyDecodingStrategy breaks dictionary-keys #4032

swift-ci opened this issue Apr 5, 2018 · 3 comments


Copy link

@swift-ci swift-ci commented Apr 5, 2018

Previous ID SR-7360
Radar None
Original Reporter dungi (JIRA User)
Type Bug
Status Resolved
Resolution Done

Xcode 9.3

Swift 4.1

macOS 10.13.4

Additional Detail from JIRA
Votes 1
Component/s Foundation
Labels Bug, Codable
Assignee None
Priority Medium

md5: ab934ce52f031c8bbf79753a55dfce79

relates to:

  • SR-10630 JSONDecoder convertToSnakeCase no longer converts dictionary keys

Issue Description:

We tried to use the new keyDecodingStategy with convertFromSnakeCase to get rid of the big CodingKey-blocks in our App. But all Keys in our dictionary are made "SnakeCase" too, which leads to problems with some of our code and frameworks.


"number_of_tables": 5,
"amount_of_workers": {
"android_developers": 4,
"ios_developers": 3

Will print:

(numberOfTables: 5, amountOfWorkers: ["androidDevelopers": 4, "iosDevelopers": 3])

instead of:

(numberOfTables: 5, amountOfWorkers: ["android_developers": 4, "ios_developers": 3])

Copy link

@belkadan belkadan commented Apr 5, 2018

I think "sometimes snake case, sometimes camel case" is something you're going to have to manage yourself. @itaiferber?

Copy link

@itaiferber itaiferber commented Apr 6, 2018

Yeah, this is the correct behavior. The encoding/decoding strategies apply to all values inside a payload — in this case, affecting Dictionary keys as well. If you need custom behavior (sometimes converting to snake_case, sometimes not), then you'll need to perform the conversion yourself.

Copy link

@itaiferber itaiferber commented May 6, 2019

This was resolved back with apple/swift#16238

@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
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

3 participants