-
Notifications
You must be signed in to change notification settings - Fork 98
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
[Question] How to serialize sum type to json? #1993
Comments
Indeed, enums (at least with arguments) can't currently be serialized. Quoting the manual:
In particular, if you just want to store a value that is either a string or a number, and serialize it without any tag (that is serialize
If for any reason you really need to keep the enum, you have to transform it to the underlying value at some point. Something like #1170 (comment) could also help, but it's an idea and isn't yet implemented, unfortunately. |
@yannham Thank you for your explaination. You explaination is very clear, I think I had use nickel in the wrong way. nickel assume the users to use it in the data-centric-way, but I use it in the type-centric-way. |
You're welcome! I'm going to close for now as the original question was mostly asking about information. Feel free to open other issues if there are other questions or proposals around enums and enums serialization in particularly. |
I also faced this issue, and this GitHub issue was the only solution I found. I think that in the docs, in the enum section, there should be a note about the pitfalls of enums (no serializability) and an explanation of how to reimplement them using |
The text was updated successfully, but these errors were encountered: