通过改造在SOAP API中获取带有响应的Null响应对象

时间:2019-04-10 11:23:08

标签: android soap kotlin retrofit retrofit2

我正在Kotlin中使用带有改造的SOAP API,因为这是SOAP API,我已经为改造后的API请求和响应创建了一个模型类,并使用该模型类进行了API调用。

这里的问题是我无法在响应模型中解析数据

下面是我需要解析的回复

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="URL" xmlns:xsi="XMLSchema" xmlns:xsd="XMLSchema">
    <soap:Body>
        <Response xmlns="URL">
            <OTA_Response Version="0">
                <Data>Hello There</Data>
            </OTA_Response>
        </Response>
    </soap:Body>
</soap:Envelope>

为了解析此响应,我创建了如下的模型类

@Root(name = "soap:Envelope", strict = false)
@NamespaceList(Namespace(prefix = "xsi", reference = "XMLSchema"),
        Namespace(prefix = "xsd", reference = "XMLSchema"),
        Namespace(prefix = "soap", reference = "URL"))

class MainResponse  @JvmOverloads constructor(
        @Element(required = true, name = "soap:Body")
        var body : Body? = null
)

@Root(name = "soap:Body", strict = false)
class Body  @JvmOverloads constructor(
        @field:Element(name = "Response", required = false)
        var ping : Response?=null
)

@Namespace(reference = "URL")
@Root(name="Response", strict = false)
class Response  @JvmOverloads constructor (
        @field:Element(name = "OTA_Response", required = false)
        var otaPingRS : OTA_Response ?=null
)


@Root(name="OTA_Response", strict = false)
class OTA_Response @JvmOverloads constructor(

        @Attribute(name = "Version")
        @param:Element
        private val Version : String? = null,

        @field:Element(name = "Data", required = false)
        @param:Element
        var data : String?=null
)

在这里,我需要从Data标签中获取Hello,但是我总是得到空值的body变量

任何帮助将不胜感激。

谢谢。

0 个答案:

没有答案