https://kotlinlang.org logo
#android
Title
# android
v

vivekneel

06/23/2017, 10:30 PM
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

gildor

06/24/2017, 6:16 AM
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