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

前端 未结 24 1799
长发绾君心
长发绾君心 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:17

    For me all I had to do was to add a constructor to the data class with empty params sent to it like so:

        @Entity(tableName = "posts")
    data class JobPost(
        @Ignore
        @SerializedName("companyLogo")
        var companyLogo: String,
        @Ignore
        @SerializedName("companyName")
        var companyName: String,
        @Ignore
        @SerializedName("isAggregated")
        var isAggregated: String,
        @PrimaryKey(autoGenerate = false)
        @SerializedName("jobID")
        var jobID: String,
        @Ignore
        @SerializedName("jobTitle")
        var jobTitle: String,
        @Ignore
        @SerializedName("postedOn")
        var postedOn: String,
        @Ignore
        @SerializedName("region")
        var region: String
    ) {
        constructor() : this("","","","","","","")
    }
    

提交回复
热议问题