Room Persistence: Error:Entities and Pojos must have a usable public constructor

前端 未结 24 1792
长发绾君心
长发绾君心 2020-12-01 09:05

I\'m converting a project to Kotlin and I\'m trying to make my model (which is also my entity) a data class I intend to use Moshi to convert the JSON responses from the API<

24条回答
  •  清歌不尽
    2020-12-01 09:24

    For a variation on FutureShocked answer that implements autoGenerate:

    @Entity(tableName = "movies")
    data class MovieKt(
            var title: String,
            var overview: String,
            var poster_path: String,
            var backdrop_path: String,
            @Ignore var release_date: String,
            @Ignore var vote_average: Double,
            @Ignore var isFavorite: Int
    ) {
    @PrimaryKey(autoGenerate = true) var id : Int = 0
    
        constructor(title: String, overview: String, poster_path: String, backdrop_path: String) {
            this(id, title, overview, poster_path, backdrop_path, "", 0.0, 0)
        }
    }
    

提交回复
热议问题