I'm attempting to use the Room TypeConverter (Room version 2.2.5) for an enum, but while compiling I receive a Class is referenced as a converter but it does not have any converter methods.
Looking at the Converter.java class, it is indeed missing the converter methods I have defined.
I've set the annotationProcessorOptions in Gradle to "room.incremental":"true"
.
Has anyone come across this issue before?
enum class Exposure(val label: String) {
SUN("Sun"),
PARTIAL_SUN("Partial sun"),
SHADE_PARTIAL_SUN("Shade, Partial sun"),
SHADE("Shade"),
SHADE_SUN("Shade, Sun");
companion object {
fun labels(): List<String> {
return values().map { it.label }.toList()
}
}
}
class Converters {
@TypeConverter
fun toExposure(value: String): Exposure {
return value.let { Exposure.valueOf(it) }
}
@TypeConverter
fun fromExposure(exposure: Exposure): String {
return exposure.name
}
}
@Entity(tableName = "plant")
data class PlantEntity(
var name: String,
var exposure: Exposure
) {
@PrimaryKey(autoGenerate = true)
var id: Int = 0
}
@Database(entities = [PlantEntity::class], version = 1, export = false)
@TypeConverters(Converters::class)
abstract class PlantDatabase : RoomDatabase() {
abstract fun plantDao(): PlantDao
...
}
Can you try using object and using
@JvmField