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

Add Key coding strategy #200

Closed
wants to merge 3 commits into from
Closed

Conversation

norio-nomura
Copy link
Collaborator

@norio-nomura norio-nomura commented Jul 7, 2019

It is a rewrite of #92.

API Changes

YAMLEncoder

  • Add KeyEncodingStrategy with cases: useDefaultKeys, convertToSnakeCase and custom(_:)
  • Copy Options from Emitter with adding keyEncodingStrategy

YAMLDecoder

  • Add KeyDecodingStrategy with cases: useDefaultKeys, useSnakeCasedKeys, useCustomizedKeys(_:) and custom(_:)
  • Add Options having keyDecodingStrategy
  • Change behaviors of allKeys:
    • Do not include duplicate keys
    • The order of the keys is no longer the same as in YAML

Difference between JSONEncoder and YAMLEncoder of KeyEncodingStrategy

The behavior is compatible with JSONEncoder. KeyEncodingStrategy

Difference between JSONDecoder and YAMLDecoder of KeyDecodingStrategy

  • Drop convertFromSnakeCase, because that has a problem: SR-6629
  • Add useSnakeCasedKeys
    That uses snake cased CodingKeys for accessing YAML contents.
    same with Add useSnakeCasedKeys to JSONDecoder.KeyDecodingStrategy swiftlang/swift#14039
    This replaces convertFromSnakeCase.
  • Add useCustomizedKeys((_ codingPath: [CodingKey]) -> CodingKey)
    That uses custom converted CodingKeys for accessing YAML contents.
  • custom((_ codingPath: [CodingKey]) -> CodingKey) is compatible with JSONDecoder's one

@doofyus
Copy link

doofyus commented Aug 12, 2019

Hi, what's the status with this one and can i be of help in moving it forward?
(KeyDecodingStrategy seems like an essential part, as Swift is commonly written in camelCase vs yaml usually in snake_case)

@beijingrice
Copy link

beijingrice commented Aug 12, 2019 via email

@beijingrice
Copy link

beijingrice commented Aug 12, 2019 via email

@jpsim jpsim closed this Dec 11, 2020
@jpsim jpsim deleted the branch master December 11, 2020 19:21
@frugoman
Copy link

Why was this closed? what's needed for this to be reopened and added to the lib? it's pretty essential

@jpsim
Copy link
Owner

jpsim commented May 31, 2021

This is definitely something I'd like to see, not sure where @norio-nomura left it off. CI was failing but it seems that Microsoft Azure Pipelines hasn't kept the results from these runs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants