【发布时间】:2021-03-12 15:35:45
【问题描述】:
我正在尝试将对象保存在房间数据库中。
我想保存在数据库中的个人资料对象类:
class Profile(
val exampleString : String = "Example String",
val exampleStringTwo : String = "Example String Two",
val subObjectsList : ArrayList<SubObjecst> = ArrayList()
)
配置文件对象包括具有此结构的子对象的 Arraylist:
class SubObjects(
val exampleString : String = "Example 1",
val exampleStringTwo : String = "Example 2",
val exampleStringThree: String = "Example 3"
)
data class ProfileEntity(
@PrimaryKey(autoGenerate = true) val id: Long?,
@ColumnInfo(name = "profile") var profille: Profile
) : Parcelable
如何在房间数据库中保存 Profile 对象?我被困在这个对象的类型转换器上。
【问题讨论】:
-
使用
GSON库将对象转换为JSONString。
标签: android kotlin android-room typeconverter