Search code examples
androidlistkotlinandroid-roomtypeconverter

How to TypeConverter List<Object> Room


I've got an error from Room: "Cannot figure out how to save this field into database. You can consider adding a type converter for it."

Here the class:

@Entity(tableName = "dictionary_table")
data class DictionaryThemeModel(
    @PrimaryKey (autoGenerate = true)
    val id: Int,
    val name: String?,
    val bestStats: Int?,
    val theme: List<DictionaryWordModel>?
)

And subclass:

data class DictionaryWordModel(
    var english: String?,
    var transcription: String?,
    var russian: String?
)

How to Convert this? I'm working without the internet. And where i have to include typeconverter then? Help pls


Solution

  • Normally, you would store primitive data types in SQL database.If you wanna save a custom data type, yo can use type converter of Room Database. The problem is the list that you are trying to save. Use a type converter for it.

    Follow this example :

    https://developer.android.com/training/data-storage/room/referencing-data