Android 房间Dao返回类型和改造api返回类型不相同(存储库模式需要相同的返回类型)
API响应:Android 房间Dao返回类型和改造api返回类型不相同(存储库模式需要相同的返回类型),android,rx-java,retrofit,repository-pattern,android-room,Android,Rx Java,Retrofit,Repository Pattern,Android Room,API响应: { "items": [ { "id": "abcd", "sku": "2134", "name": "Blue Jeans", "price": { "current": 4.99, "original": 7.99, "currency": "EUR" }, "brand": "Reebok", "image": "www.google.com", "published_at": "2015-09-
{
"items": [
{
"id": "abcd",
"sku": "2134",
"name": "Blue Jeans",
"price": {
"current": 4.99,
"original": 7.99,
"currency": "EUR"
},
"brand": "Reebok",
"image": "www.google.com",
"published_at": "2015-09-22 17:43:12",
"is_active": true
},
{
"id": "efgh",
"sku": "123",
"name": "Black Jeans",
"price": {
"current": 6.99,
"original": 8.99,
"currency": "EUR"
},
"brand": "Nike",
"image": "www.google.com",
"published_at": "2015-09-02 10:35:07",
"is_active": true
}
]
}
房间:
@Dao
interface ProductsDao {
@Query("SELECT * FROM product")
fun queryProducts(): Single<List<Product>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertProduct(product: Product)
}
@Dao
接口产品DAO{
@查询(“从产品中选择*)
趣味queryProducts():单个
@插入(onConflict=OnConflictStrategy.REPLACE)
fun insertProduct(产品:产品)
}
API方法:
@GET()
fun getProducts(@Url format: String): Observable<ProductsResponse>
@GET()
fun getProducts(@Url格式:String):可观察
产品响应类别:
data class ProductsResponse(
val items: List<Product>
)
数据类产品响应(
val项目:列表
)
现在,当我尝试为离线第一个应用程序实现存储库模式时,我需要我的房间数据库和API返回相同类型的数据。我如何才能做到这一点?名称映射实际上不是一个问题。问题是我的API调用返回一个可观察的,但我的DB调用返回一个可观察的。当我实现存储库模式时,我需要API和DB返回相同的类型。