简体   繁体   中英

Integrating greenDAO and Jackson

I am working on a project with an Android side and a backend, and for the JSON parsing I am using Jackson library on both sides. Using Play 2.0 for the backend, Ebean is Jackson annotations friendly, but the problem is with GreenDAO, since GreenDAO uses code generation, I have to type again all the annotations every time I migrate the database. I searched around and found only
this question but I can't find any template file.

I am using GreenDao 2.2.0.

I found that instead of adding the annotations in the Model itself, according to the documentation of the modelling you can use methods like setCodeBeforeClass(String code) and codeBeforeField(String code) to add the annotations, for example in the Generator Module

schema.enableKeepSectionsByDefault();

    Entity gItem= schema.addEntity("GrItem");
    gItem.setCodeBeforeClass("@JsonSerialize(using = ItemSerializer.class)"+"\n"+"@JsonIgnoreProperties(ignoreUnknown = true)");
    gItem.addIdProperty().codeBeforeField("@JsonProperty(\"id\")");

thus every time you run the generator you can still generate the annotations with the code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM