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

Support serialization key transformer #48

Closed
MP0w opened this issue Apr 26, 2016 · 0 comments
Closed

Support serialization key transformer #48

MP0w opened this issue Apr 26, 2016 · 0 comments

Comments

@MP0w
Copy link
Member

MP0w commented Apr 26, 2016

In swift code we usually use camelCase while for JSON other convention (mostly snake_case) are used, I would don't like forcing the user to name the property we might have easy ways to support this:

Detailed design

SnakeCaseTransformer(User()) // convert the serialized object to snake case

This can be done by using CustomSerializable.
It would be good if the transformed can also be used to rename properties of an entity:

struct User: Serializable {
   let id: Int
}

// you want id (Storable) to be named `userId` in the JSON

protocol KeyTransformer: CustomSerializable {
    func transformedKey(for candidate: String) -> String
}

extension KeyTransformer {
// default implementation that use `transformedKey...`to transform the keys
}
@MP0w MP0w self-assigned this Apr 26, 2016
@MP0w MP0w modified the milestones: Beta-1, Alpha-3 Apr 26, 2016
@MP0w MP0w removed this from the Beta-1 milestone Jun 12, 2016
@MP0w MP0w closed this as completed in #74 Jun 30, 2016
@zzarcon zzarcon reopened this Jun 30, 2016
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

3 participants