Set codeBeforeField for attribute before GreenDAO relation

216 Views Asked by At

I have recently started using GreenDao for my Android app where I am creating a Category entity which should have multiple Category entities as children. Therefore I am using a 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 is creating the correct code as required where I have the following:

private List<Category> children;

The problem

The problem is that I need to use a @SerializedName attribute before this property because I am parsing some json (obtained from another service) with different field names into these Category entities.

For other properties, I am using the codeBeforeField() method which generates the attribute correctly:

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

Is there any way to set the codeBeforeField on this 'children' property in order to add @SerializedName attribute? Or perhaps there is some other way to generate this attribute before my 'children' property?

I have tried searching for ways so set this on the relation but it seems that this method is only available on PropertyBuilder. Is there any way to perhaps retrieve the PropertyBuilder from the ToMany relation?

Any help would be appreciated. Thank you.

0

There are 0 best solutions below