如何在模型类中转换字符串的嵌套Jsonarray-Room

时间:2019-05-03 12:15:12

标签: json database kotlin retrofit android-room

我正在尝试使用Seriazable(在Model类内部)转换Strings的JsonArray,但是应用程序始终崩溃

  

AppComponent.java:11:错误:[ComponentProcessor:MiscError]   dagger.internal.codegen.ComponentProcessor无法处理此问题   接口,因为不是所有的依赖关系都可以解决。校验   编译错误或生成代码的循环依赖性。

这是列表中的一项(改进)。当我尝试解析颜色数组时出现了我的问题

{
        "id": 12,
        "title": "Event",
        "start_date": 1557219638,
        "end_date": 1557222342,
        "workshop": {
            "id": 13,
            "title": "Event",
            "appearance": {
                "id": 1,
                "name": "Teal",
                "type": "Gradient",
                "colours": [
                    "#1da8b3",
                    "#4ac6d1"
                ]
            }
        }
}

和模型类

@Entity(tableName = "Event")
data class Event(

    @PrimaryKey
    @SerializedName("id")
    var id: Int,

    @SerializedName("title")
    var title : String,

    @SerializedName("start_date")
    var startDate : Int,

    @SerializedName("end_date")
    var endDate : Int,
    @Embedded
    @SerializedName("workshop")
    var workshop: Workshop

) :Serializable {}

@Entity(tableName = "Workshop")
data class Workshop(

    @PrimaryKey
    @SerializedName("id")
    var idW: Int,

    @SerializedName("title")
    var titleW : String

    @Embedded
    @SerializedName("appearance")
    var appearance: Appearance
) : Serializable {
}

@Entity(tableName = "Appearance")
data class Appearance(

    @PrimaryKey
    @SerializedName("id")
    var id :Int,
    @SerializedName("name")
    var name : String,

    @SerializedName("type")
    var type :String,

    @ColumnInfo(name = "colours") //here is the problem
    var colours: List<String>

) :Serializable {

   constructor(): this(0,"","","", listOf(),0)
}

在这一点上,我不知道如何解析颜色[]。我应该使用其他模型类吗?

0 个答案:

没有答案