我正在使用 Retrofit 进行 API 调用。我能够缓存仅包含字符串和 int 的数据类。但现在我想缓存另一个具有嵌套模型类的模型类,如下所示。
@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)