Android Room Persistence library entity with AutoValue

Viewed 2484
5 Answers

Released in 2.1.0-alpha01!

Note that you have to add the @CopyAnnotations annotation for it to work

Auto Value: Room now supports declaring AutoValue annotated classes as entities and POJOs. The Room annotations @PrimaryKey, @ColumnInfo, @Embedded and @Relation can now be declared in an auto value annotated class’ abstract methods. Note that these annotation must also be accompanied by @CopyAnnotations for Room to properly understand them.

see the release notes

Following this task, apparently they added support. I assume it will be possible in the future Room release (probably androidx.room version 2.0.0). Still not merged as part of 2.0.0-beta1 though

Now it is possible with the Room database 2.1.0.

You can make this possible by annotating the abstract class methods with @PrimaryKey, @ColumnInfo, @Embedded, and @Relation. The abstract class has to be annotated with @Autovalue.

Related