参数不匹配;简单XML [英] Parameter does not have a match; SimpleXML
本文介绍了参数不匹配;简单XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I am using retrofit
with the SimpleXMLConverterFactory
.
And I always get an
ConstructorException: Parameter 'success' does not have a match in class ResponseInfo
And I have no idea what could be wrong. The xml is very simple and i only want the string from the success
node.
xml:
<?xml version="1.0" encoding="UTF-8"?>
<response>
<success>LoremIpsum</success>
</response>
ResponseInfo:
@Root(strict = false, name = "response")
data class ResponseInfo(@Element(required = false, name = "success) var success: String)
Edit 1: I tested the Api call and it returns the given xml.
Thanks
解决方案
So finally, I managed to solve the problem myself.
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.
这篇关于参数不匹配;简单XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文