Hello , How can i convert custom class to a type...
# android
v
Hello , How can i convert custom class to a type that room can recognise and persist , afaik room persist only primitive data type. I have something like this :
Copy code
@Entity(tableName = CricketConfig.TABLE_NAME)
data class CricketModel(@PrimaryKey(autoGenerate = true) var id : Int = 0 ,@SerializedName("matches") var matches: List<Match> = emptyList())
Now i need to convert
List<Match>
to a type that room can recognize , any idea on how to achieve this?
g
For custom type you can use type convertor https://developer.android.com/topic/libraries/architecture/room.html#type-converters But keep list of entities in database field is not possible out of the box. Maybe better use separate table for them Of course you can serialize this list manually for example use Json, but I'm not sure that it's best solution in your case
👍 1