注释greenDao生成的对象

use*_*284 4 orm android greendao

我看到,由于性能问题,greenDao不希望使用注释来生成DAO和TO.但是,如果我仍然需要为解析器目的注释例如TO?有没有办法实现这一目标?

例:

如果我们使用GreenDAO代码生成创建Customer实体,它将创建CustomerDAO和Customer类,对吧?

那么,如果我正在使用返回Customer对象的SOAP webservices,并且为了便于解析这个Customer对象,我会使用一个带注释的框架,比如simpleXML.在使用GreenDAO重新生成代码时,有没有办法更改Customer类而不会松散每个注释?

谢谢!

ars*_*ent 9

您可以像这样添加greendao 2.0注释

entity.addStringProperty("title").codeBeforeField("@com.google.gson.annotations.SerializedName( \"title\" )");
Run Code Online (Sandbox Code Playgroud)

  • 或`entity.addImport("com.google.gson.annotations.SerializedName"); entity.addLongProperty("mobile").codeBeforeField("@ SerializedName(\"mobile \")");`:) (3认同)

yig*_*git 5

你可以尝试在Path中使用我们的fork,它增加了对Annotations的支持.(它还增加了对枚举和序列化的支持) https://github.com/path/greenDAO 它在我的盘子上发送拉取请求但不确定我什么时候有空.

顺便说一句,我们的版本没有经过单元测试,因为我们已经在生产中使用了一段时间,所以应该足够稳定.

要添加注释,您可以查看以下示例代码:https: //github.com/path/greenDAO/blob/master/DaoExampleGenerator/src/de/greenrobot/daogenerator/gentest/ExampleDaoGenerator.java#L42

顺便说一句,我们的fork为每个Entity对象创建两个类.一个EntityBase抽象的,包括所有领域等,Entity并扩展EntityBase.你应该只编辑Entity.