Parsing a nested JSON data with gson and saving it in local db using room. However, I keep getting the following exception
error: Not sure how to convert a Cursor to this method's return type (kotlinx.coroutines.flow.Flow<java.util.TreeMap<java.lang.String,java.util.ArrayList<com.Category>>>).
Would need some help in solving this issue. Can anyone point out what am I missing Thanks!
response.json
{
"data": {
"Category1": [
{
"data": "xyz",
"value": "",
"type": "",
"title": ""
},
{
"data": "xyz",
"value": "",
"type": "",
"title": ""
},
{
"data": "xyz",
"value": "",
"type": "",
"title": ""
}
],
"Category2": [
{
"data": "xyz",
"value": "",
"type": "",
"title": ""
},
{
"data": "xyz",
"value": "",
"type": "",
"title": ""
},
{
"data": "xyz",
"value": "",
"type": "",
"title": ""
}
],
"Category3": [
{
"data": "xyz",
"value": "",
"type": "",
"title": ""
},
{
"data": "xyz",
"value": "",
"type": "",
"title": ""
},
{
"data": "xyz",
"value": "",
"type": "",
"title": ""
}
]}}
Following is my response class
data class CategoryShowResponse (
@SerializedName("data")
val categoryShowResponse: TreeMap<String,ArrayList<Category>>)
Below is my Category class
@Entity(tableName = TABLE_NAME)
data class Category(
@SerializedName( "data") val data: String,
@SerializedName("value") val value: String,
@SerializedName( "type") val type: String,
@SerializedName( "title") val title: String) {
companion object {
const val TABLE_NAME = "Category_data"
}}
Below is in AppDatabase.class
@Database(
entities = [Category::class],
version = DatabaseMigrations.DB_VERSION)
abstract class _Database: RoomDatabase() {
abstract fun getCategorizedDao(): CategorizedDao}
Finally my CategoryDao class
@Dao
abstract class CategoryDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract fun insertCategorizedShows(shows: TreeMap<String, ArrayList<Category>>)
@Query("DELETE FROM ${Category.TABLE_NAME}")
abstract fun deleteAllCategories()
@Query("SELECT * FROM ${Category.TABLE_NAME}")
abstract fun getAllCategories(): Flow<TreeMap<String, ArrayList<Category>>>}
I keep getting the following exception
error: Not sure how to convert a Cursor to this method's return type (kotlinx.coroutines.flow.Flow<java.util.TreeMap<java.lang.String,java.util.ArrayList<com.Category>>>).
Would need some help in solving this issue