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

Customize the decoder with a keyDecodingStrategy #7

Open
kevinrenskers opened this issue Apr 5, 2019 · 0 comments
Open

Customize the decoder with a keyDecodingStrategy #7

kevinrenskers opened this issue Apr 5, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@kevinrenskers
Copy link

kevinrenskers commented Apr 5, 2019

I'd like to be able to set the keyDecodingStrategy of the default JSONDecoder to .convertFromSnakeCase, but that doesn't seem possible at the moment?

So instead I now have to give the CodingKeys by hand.

struct Upload: Codable {
  let id: Int
  let user: User
  let mediaType: String
  let image: String
  let thumbnail: String
  let description: String

  enum CodingKeys: String, CodingKey {
    case id
    case user
    case mediaType = "media_type"
    case image
    case thumbnail
    case description
  }
}

This is a little bit annoying considering all of that could be automated away with setting the keyDecodingStrategy :)

This could be done the same way that the date encoding strategy can already be customized.

@kevinrenskers kevinrenskers changed the title Customize the decoder with a Customize the decoder with a keyDecodingStrategy Apr 5, 2019
@MihaelIsaev MihaelIsaev added the enhancement New feature or request label Apr 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants