Reputation: 93
I see that greenDao prefers not to use annotations for DAO and TO generation due to performance issues. However what if I still need to annotate for instance a TO for parser purposes? Is there any way to achieve that?
Example:
If we create a Customer entity with GreenDAO code generation, it will create the CustomerDAO and the Customer classes, right?
So, what if I`m consuming SOAP webservices, which returns a Customer object, and to facilitate parsing this Customer object I use an annotated kind of framework like simpleXML. Is there any way to change the Customer class without loose every annotation when regenerating code with GreenDAO?
Thanks!
Upvotes: 4
Views: 3429
Reputation: 7183
You can add annotations with greendao 2.0 like this
entity.addStringProperty("title").codeBeforeField("@com.google.gson.annotations.SerializedName( \"title\" )");
Upvotes: 9
Reputation: 38253
you can try using our fork at Path which adds supports for Annotations. (it also adds support for enum and serialization) https://github.com/path/greenDAO it is on my plate to send a pull request for it but not sure when I'll have time.
btw, our version is not well unit-tested as greenDAO but we've been using it on production for a while so should be stable enough.
To add annotations, you can check this sample code: https://github.com/path/greenDAO/blob/master/DaoExampleGenerator/src/de/greenrobot/daogenerator/gentest/ExampleDaoGenerator.java#L42
btw, our fork creates two classes for each Entity object. An EntityBase
which is abstract and includes all fields etc and an Entity
which extends EntityBase
. You should only edit Entity
.
Upvotes: 5