我有一个数据类存储在数据库中。
@kotlinx.serialization.Serializable
data class SavedCalculation(
override val id: String,
val model1: Model1,
val model2: Model2
):org.kodein.db.model.orm.Metadata {
}
@kotlinx.serialization.Serializable
data class Model1(
var attr1: String = "",
var attr2: String = "",
)
@kotlinx.serialization.Serializable
data class Model2(
var attr1: String = "",
var attr2: String = "",
)
如果我在视图模型中调用我的savedCalculation对象;
var saved = mutableStateOf<List<SavedCalculation>>(listOf())
private set
fun load(){
viewModelScope.launch {
useCases.load.invoke().collect { response ->
when(response){
is Response.Loading -> {
}
is Response.Success -> {
saved.value = response.data
saved.value[0].model1 -> **this causes error.**
}
is Response.Error -> {}
}
}
}
}
错误:
无法访问"org.kodein.db.model.orm.HasMetadata",它是"com.myapp.data.model.SavedCalculationDto"的超类型。请检查模块类路径是否存在丢失或冲突的依赖项
我的主包和数据包是单独的渐变构建文件,因此kodeidb无法从我的视图模型访问依赖项。我只是在我的build.gradle.kts中添加了相同的kodeidb依赖项,我的问题就解决了。
//into viewmodel package gradle file:
implementation("org.kodein.db:kodein-db-jvm:0.8.1-beta")
implementation("org.kodein.db:kodein-db-serializer-kotlinx:0.8.1-beta")
implementation("org.kodein.db:kodein-leveldb-jni-jvm-windows:0.8.1-beta")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")