Integrating greenDAO and Jackson

317 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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