I want to store the following dataclass in my room database. Somehow, I do not succeed:
@Entity
data class UInt8(
@PrimaryKey(autoGenerate = true)
var key: Int,
var name: String = "uint8-test",
var value: UByte = 0.toUByte(),
var size: Int = 1,
var readOnly: Boolean = true
)
I always get the error for my auto-generated build files:
C:<...>\UInt8.java:15: error: Cannot find getter for field.
private byte value;
Cannot find getter for field.
Same for UShort
, UInt
and ULong
.
However, If I replace it by an Int
, it seems to work, but is not what I intented (it needs to be an UByte.
build.grade
(from developer.android.com):
def room_version = "2.4.2"
//implementation "androidx.room:room-runtime:$room_version"
//annotationProcessor "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:$room_version"
kapt "androidx.room:room-compiler:2.5.0-alpha01"
// kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.2.0"
// optional - RxJava2 support for Room
implementation "androidx.room:room-rxjava2:$room_version"
// optional - RxJava3 support for Room
implementation "androidx.room:room-rxjava3:$room_version"
// optional - Guava support for Room, including Optional and ListenableFuture
implementation "androidx.room:room-guava:$room_version"
// optional - Test helpers
testImplementation "androidx.room:room-testing:$room_version"
// optional - Paging 3 Integration
implementation "androidx.room:room-paging:2.5.0-alpha01"
Update 1:
My TypeConverter (Converters.kt
) looks the following:
class Converters {
@TypeConverter
fun uByteToInt(uByte: UByte): Int = uByte.toInt()
@TypeConverter
fun intToUByte(value: Int): UByte = value.toUByte()
}
and AppDatabase.kt
:
@Database(entities = [<...>::class], version = 1, exportSchema = false)
@TypeConverters(Converters::class)
abstract class AppDatabase : RoomDatabase() {
abstract fun sensorDao(): SensorDao
...
}
Update 2:
Probably it is noteworthy that the Class UInt8
is a nested class in another Entity, i.e.:
@Entity()
data class simpleConfig(
@Embedded(prefix = "simplec_version_") val version: UInt8 =
UInt8("Field Version"),
...)