【问题标题】:Integrating greenDAO and Jackson整合 greenDAO 和 Jackson
【发布时间】:2016-06-19 09:54:28
【问题描述】:
我正在开发一个带有 Android 端和后端的项目,对于 JSON 解析,我在两端都使用了 Jackson 库。
后端使用 Play 2.0,Ebean 对 Jackson 注释很友好,但问题出在 GreenDAO,因为 GreenDAO 使用代码生成,每次迁移数据库时我都必须重新输入所有注释。
我四处寻找,只找到了
this question,但我找不到任何模板文件。
我正在使用 GreenDao 2.2.0。
【问题讨论】:
标签:
android
jackson
greendao
greendao-generator
【解决方案1】:
我发现不用在Model本身添加注解,根据documentation of the modelling可以使用setCodeBeforeClass(String code)和codeBeforeField(String code)等方法添加注解,
例如在生成器模块中
schema.enableKeepSectionsByDefault();
Entity gItem= schema.addEntity("GrItem");
gItem.setCodeBeforeClass("@JsonSerialize(using = ItemSerializer.class)"+"\n"+"@JsonIgnoreProperties(ignoreUnknown = true)");
gItem.addIdProperty().codeBeforeField("@JsonProperty(\"id\")");
因此,每次运行生成器时,您仍然可以使用代码生成注释