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
How to serialize enum to actual json number #2623
Comments
As a workaround you may have to implement a customized serializer |
You can use enumAsOrdinalSerializer from my complementary library if you'd like. Or just yank code from there to get a starting point. Note that it uses the ordinal value for the enum entries, so |
@Kantis thanks, I've already made my own custom (de)serializer, though I'll take a look at your solution. |
Note that |
@sandwwraith Yes, I know |
I don't think that is really possible at the moment. However it is certainly possible to have "canned" serializers that you just apply on a type. It would be interesting though to have an additional parameter to There is a bit of a challenge in implementing this. It is possible to implement the new function as a default interface implementation that passes to the original function. This retains compatibility. This however means that for implementation of the new interface the old functions will also need to be implemented, perhaps this is still better though than having both functions default implemented and referring to each other (which would also be binary compatible, but be poor API design). |
Code above prints:
How to make it print:
I.e. use proper json number as enum encoded value?
The text was updated successfully, but these errors were encountered: