Skip to content

Customize the decoder with a keyDecodingStrategy #7

@kevinrenskers

Description

@kevinrenskers

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions