Set the CodeBeforeField parameter to the attribute before the GreenDAO relation

I recently started using GreenDao for my Android application, where I create a Category object, which should have several category objects as children. Therefore, I use Tree Relation as follows:

Entity category = schema.addEntity("Category"); ... Property parentIdProperty = category.addLongProperty("parentId").getProperty(); category.addToOne(category, parentIdProperty).setName("parent"); category.addToMany(category, parentIdProperty).setName("children"); 

This creates the correct code if required, where I have the following:

 private List<Category> children; 

Problem

The problem is that you need to use the @SerializedName attribute before this property, because I am parsing some json (received from another service) with different field names in these Category objects.

For other properties, I use the codeBeforeField () method, which correctly generates an attribute:

 category.addStringProperty("categoryId").codeBeforeField("@SerializedName( \"Id\" )"); 

Is there a way to set the BeForeField code for this children property to add the @SerializedName attribute? Or maybe there is another way to generate this attribute before my "children" property?

I tried to find ways to set this in relation, but it seems that this method is only available in PropertyBuilder. Is there a way to extract a PropertyBuilder from a ToMany relationship?

Any help would be greatly appreciated. Thanks.

+5
source share

Source: https://habr.com/ru/post/1243765/


All Articles