-
Notifications
You must be signed in to change notification settings - Fork 139
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
Support enum encoding #307
base: series/1.x
Are you sure you want to change the base?
Conversation
@fommil I’d appreciate your opinion here. |
conceptually this is nice but it is too magical for my personal tastes. I'd rather this was its own macro. Firstly it breaks backwards compatibility, and secondly it means that your entire sealed trait encoding can change just because you add a non |
I agree, especially regarding the backwards compatibility and the lexer/exceptions part. |
@jgoday If we implement this with another macro, we could keep compatibility and fail compilation if not every member of the sealed hierarchy is a case object — wdyt? |
@jgoday |
@fsvehla, I have implemented it like this jgoday@2f7160a Two different macros (DeriveJsonDecoderEnum/DeriveJsonEncoderEnum) only for the sealed traits/case objects like enums. Is this a valid approach ? If so, we should implement toJsonAST/fromJsonAST tests and keep running existing annotations with the new encoder/decoder for enums. |
From #105.
It allows to encode/decode enums (as sealed traits and case objects) like
I think that some things needs some revision or maybe a different/better solution:
1 - When decoding a SealedTrait, lexer tries to consumes '{', if it throws an UnsafeJson exception, we try to match an enum value.
2 - Find a better approach to determine if an object is a case object (should work in scala.js too)