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

Serialize enums to member names instead of values in JSON/YAML #20

Closed
docelic opened this issue Sep 8, 2021 · 0 comments
Closed

Serialize enums to member names instead of values in JSON/YAML #20

docelic opened this issue Sep 8, 2021 · 0 comments

Comments

@docelic
Copy link
Contributor

docelic commented Sep 8, 2021

In Crystal, enums are serialized to member names by default.

It would be great to have a choice between names and values in JSON/YAML too.

A slight complication is that, in the case of Flags Enums, the serialization ends up being an array with all active members listed:
https://github.com/crystal-lang/crystal/blob/b88b842d425de7ce2a74c1acf82b30c447e1b254/src/json/to_json.cr#L198

And that requires more meta information to be passed to the (de)serialize overloads for Enums than that which is currently available.

j8r added a commit that referenced this issue Sep 8, 2021
j8r added a commit that referenced this issue Sep 9, 2021
@j8r j8r closed this as completed Sep 9, 2021
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

No branches or pull requests

2 participants