我正在对API调用使用改造。 我能够缓存仅包含字符串和整数的数据类。 但是现在我想缓存另一个具有嵌套模型类的模型类 在下面。
@Entity data class ConsumptionDashboardResponse(
@Id(assignable = true)
var id: Long? = null,
@Transient
@SerializedName("data")
@NameInDb("data_consumption")
var `data`: DataConsumption,
@SerializedName("responseCode")
val responseCode: Int,
@SerializedName("responseDesc")
val responseDesc: String,
@SerializedName("sessionLang")
val sessionLang: String )
数据消费类:
@Entity
data class DataConsumption(
@Id(assignable = true)
var id: Long? = null,
@Backlink
@Transient
@SerializedName("listDivisions")
var listDivisions: List<Divisions>
)
和师类
@Entity
data class Divisions(
@Id(assignable = true)
var id: Long? = null,
@SerializedName("aggregateBalance")
val aggregateBalance: String,
@SerializedName("aggregateConsumption")
val aggregateConsumption: String,
@SerializedName("division")
val division: String,
@Backlink
@Transient
@SerializedName("listConsumption")
var listConsumption: List<Consumption>,
@SerializedName("unit")
val unit: String
)
细分类别包含“消费”列表
@Entity
data class Consumption(
@Id(assignable = true)
var id: Long? = null,
@SerializedName("aggregateConsumption")
val aggregateConsumption: String,
@SerializedName("billingPeriod")
val billingPeriod: String
)
我找不到我是否需要任何类型的自定义转换器或需要做的其他事情。
如果我尝试从ObjectBox读取保存的数据,这就是我得到的:
ConsumptionDashboardResponse(id=4, data=null, responseCode=200, responseDesc=SUCCESS, sessionLang=AR)