Retrofit2 + SimpleXML in Kotlin: MethodException: Annotation must mark a set or get method

后端 未结 3 1593
清酒与你
清酒与你 2020-12-08 11:03

I want to fetch XML data from API and map it to Kotlin model object by using Retrofit2 + SimpleXML in Kotlin.

However, I got such as the following error message from

3条回答
  •  执笔经年
    2020-12-08 11:32

    Not familiar with the SimpleXml library but if it's annotation processor is looking for specific get and set methods you may want to try setting up your class in the following way:

    @Root(name="response") class User() {
    var result:String?=null
        @Element
        get
        @Element
        set
    var token:String?=null
        @Element
        get
        @Element
        set
    var uid:String?=null
        @Element
        get
        @Element
        set
    }
    

    As well, if the @Element annotation supports field types you could use this approach:

    @Root(name="response") class User() {
        @Element @JvmField var result:String?=null
        @Element @JvmField var token:String?=null
        @Element @JvmField var uid:String?=null
    }
    

提交回复
热议问题