Parameter does not have a match; SimpleXML

前端 未结 2 766
轮回少年
轮回少年 2020-12-10 15:18

I am using retrofit with the SimpleXMLConverterFactory.

And I always get an

ConstructorException: Parameter \'success\' do         


        
相关标签:
2条回答
  • 2020-12-10 15:31

    So finally, I managed myself to solve the problem.

    The problem was the ResponseInfo class. After I changed it to

    @Root(strict = false, name="response)
    data class ResponseInfo @JvmOverloads constructor(
      @field:element(name = "success") var success: String = ""
    )
    

    all worked fine.

    You need to have an empty constructor, all properties must be mutable (var) and you have to append field: in front of the @Element-Annotation. @JvmOverloads combined with default values will create the empty constructor for you as well as all other constructor variations.

    0 讨论(0)
  • 2020-12-10 15:43

    If you want to avoid having a deafult constructor, you would have to use both field and param use-site targets. It would look something like this:

    @Root(strict = false, name = "response")
    data class ResponseInfo(
        @field:Element(name = "success") @param:Element(name = "success") var success: String
    )
    

    As stated in this comment it seems like there isn't any way of combining the two use-site targets.

    0 讨论(0)
提交回复
热议问题