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

Enums support in annotation processors #730

Open
geralt-encore opened this issue Dec 8, 2016 · 10 comments
Open

Enums support in annotation processors #730

geralt-encore opened this issue Dec 8, 2016 · 10 comments

Comments

@geralt-encore
Copy link
Collaborator

What are your thoughts on this feature? Would be happy to implement it.

@nikitin-da
Copy link
Collaborator

It would be great!
But how can we perform serialization? Should it be some db value extractor or just ordinal value? (danger for persistence in case when we will add new item in the middle ordinal will be shifted) =(

@geralt-encore
Copy link
Collaborator Author

You are right about ordinal. But what about valueOf? Then we can just save String representation of enum.

@nikitin-da
Copy link
Collaborator

Oh yeah, with name - valueOf it should work! 👍

@artem-zinnatullin
Copy link
Member

artem-zinnatullin commented Dec 9, 2016 via email

@geralt-encore
Copy link
Collaborator Author

Wow, thanks, @artem-zinnatullin, for a really good point! I haven't thought about it.
So looks like that we have to options and both of them aren't perfect. Using ordinal can cause potential issues with changing order of enum members. And using valueOf can cause issues with Proguard and additional headache for users because of it. What will be the best option you think? Or maybe I missed something?

@artem-zinnatullin
Copy link
Member

artem-zinnatullin commented Dec 13, 2016 via email

@RickBoyerDev
Copy link

From experience with other ORM's, I wouldn't use either the ordinal or name, instead I implemented an "id" for each enum and persisting the id.

@geralt-encore
Copy link
Collaborator Author

SQLDelight uses just valueOf for mapping enums.

@RickBoyerDev
Copy link

Yeah, that's actually how I persisted my enums before as well. Then when I was working with greenDAO, I came across this:

How to convert Enums correctly
Enums are popular with data objects like entities. When persisting enums, there are a couple of best practices:
Do not persist the enum’s ordinal or name:
http://greenrobot.org/greendao/documentation/custom-types/

The biggest problem I see is if Proguard obfuscates the enum names, so I switched to implementing custom IDs.

@artem-zinnatullin
Copy link
Member

The biggest problem I see is if Proguard obfuscates the enum names

You are in control of that

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

4 participants