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

Be able to use own encoder and decoder. #1080

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

noppefoxwolf
Copy link
Contributor

No description provided.

let encoder: JSONEncoder
let decoder: JSONDecoder

public init(decoder: JSONDecoder = .init(), encoder: JSONEncoder = .init()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you decided to create an initializer for these properties?

I think this development is unnecessary to use encoder and decoder because these properties aren't use anywhere except functions.

On the other hand some cases we don't need to create encoder or decoder.
For example; if data comes NULL in transformFromJSON (_ value:) -> Object? function returns immediately from guard statement and we don't create a decoder.

transformToJSON (_ value: ) -> JSON? has a same case, if value comes NULL we don't create encoder.

What do you think about this cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to set options for JSONDecoder and JSONEncoder.
For example, cannot set dataDecodingStrategy by current code.


public init() {}
let encoder: JSONEncoder
let decoder: JSONDecoder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should consider making those properties private. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES, serializers should be private.

Sources/CodableTransform.swift Outdated Show resolved Hide resolved
Sources/CodableTransform.swift Outdated Show resolved Hide resolved
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.

3 participants