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

Introduce a flag to default toEncoding to Generic rather than an implementation in terms of toJSON #939

Closed

Conversation

TeofilC
Copy link
Contributor

@TeofilC TeofilC commented May 9, 2022

This adds a flag (alternative names appreciated) that defines the default toEncoding method of ToJSON in terms of Generics rather than the toJSON method. This introduces symmetry between the toJSON and toEncoding methods, and makes it a lot easier to try to eliminate uses of toJSON from a codebase.

This change is placed behind a flag as it would break code that doesn't use Generic deriving and instead only gives an implementation of toJSON.

@phadej
Copy link
Collaborator

phadej commented May 9, 2022

I'd rather introduce a newtype to use DerivingVia as mentioned in #933

Flag will change behavior for everyone, and that's quite a sledgehammer approach.

@TeofilC
Copy link
Contributor Author

TeofilC commented May 9, 2022

This flag would be off by default. But if your preference is to go for DerivingVia that makes sense.

I would still like a flag that disables the default instance of toEncoding in terms of toJSON though as it makes it viable to find cases where a toEncoding instance was missed. This would be off be default. What do you think of that?

@phadej
Copy link
Collaborator

phadej commented May 9, 2022

My (#933) long term plan is to remove default implementation all-together.

Current default implementation is broken, but changing it doesn't make sense (unnecessary "breakage" in between) as DerivingVia will be more explicit and configurable.

@TeofilC
Copy link
Contributor Author

TeofilC commented May 9, 2022

Sure that makes sense and I agree is the right approach.
If you're not interested in having a flag for this in the interm I'll close this PR.

@TeofilC TeofilC closed this May 9, 2022
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.

2 participants