I have a problem with room.
I'm using retrofit with Gson converter for the rest api, and I'd like to share the pojos with room. In general it works, but in some cases I need to ignore some fields, because I have list of objects. I tried to use the @Ignore annotation, but using it the build process fails with the following errors:
error: Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type). public final class Service {
^ error: Cannot find setter for field. private final java.lang.String id = null;
^ error: Cannot find setter for field. private final java.lang.String name = null;
^ error: Cannot find setter for field. private final java.lang.String description = null;
So, using this class, everything works:
@Entity(tableName = "services")
data class Service(
@PrimaryKey val id: String,
val name: String,
val description: String,
val parentId: String?
)
With this, fails:
@Entity(tableName = "services")
data class Service(
@PrimaryKey val id: String,
val name: String,
val description: String,
val parentId: String?,
@Ignore val test: String
)
I'm using this version of room:
implementation 'androidx.room:room-runtime:2.1.0-alpha06'
kapt 'androidx.room:room-compiler:2.1.0-alpha06'
I know that the problem could be fixed using var instead of val and adding a secondary constructor, but I don't want to do that, I prefer to preserve the immutable state of my fields.
Is it a bug of the ignore annotation? Why without it everything works? Any help is appreciated :)