gpt4 book ai didi

android - 无法使用 SimpleXML 反序列化 SOAP 响应?

转载 作者:行者123 更新时间:2023-11-30 00:51:11 27 4
gpt4 key购买 nike

我正在开发一个用于与本地设备进行 UPnP 连接的库。尝试解析来自其中一个操作的响应时,出现以下异常:

问题: org.simpleframework.xml.core.ValueRequiredException:无法满足@org.simpleframework.xml.Element(data=false, name=s:Body, required=true , type=class com.stuff.AssignedRolesResponseBody) 在字段 'responseBody' 私有(private) com.stuff.AssignedRolesResponseBody com.stuff.AssignedRolesResponseEnvelope.responseBody 类 com.stuff.AssignedRolesResponseEnvelope 在第 1 行

我正在尝试解析的原始响应:

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetAssignedRolesResponse xmlns:u="urn:schemas-upnp-org:service:DeviceProtection:1">
<RoleList>{something_here?}</RoleList>
</u:GetAssignedRolesResponse>
</s:Body>
</s:Envelope>

这些是我的 POJO:

响应信封:

@Root(name = "s:Envelope")
@NamespaceList({
@Namespace(prefix = "s", reference = "http://schemas.xmlsoap.org/soap/envelope/")
})
public class AssignedRolesResponseEnvelope extends XMLBaseResponse {

@Element(name = "s:Body", type = AssignedRolesResponseBody.class)//I tried without specifiying the type here - no difference
private AssignedRolesResponseBody responseBody;

public AssignedRolesResponseBody getResponseBody() {
return responseBody;
}

public void setResponseBody(AssignedRolesResponseBody responseBody) {
this.responseBody = responseBody;
}
}

正文:

public class AssignedRolesResponseBody {

@Element(name = "u:GetAssignedRolesResponse")
@NamespaceList({
@Namespace(prefix = "u", reference = "urn:schemas-upnp-org:service:DeviceProtection:1")
})
private AssignedRolesResponseAction action;

public AssignedRolesResponseAction getAction() {
return action;
}

public void setAction(AssignedRolesResponseAction action) {
this.action = action;
}
}

Action :

public class AssignedRolesResponseAction {

@Element(name = "RoleList")
List<String> roleList;

public List<String> getRoleList() {
return roleList;
}

public void setRoleList(List<String> roleList) {
this.roleList = roleList;
}
}

非常感谢任何输入。

最佳答案

我会回答我自己的问题。我做了 3 处更改来解决此问题:

1).也映射了 encodyngStyle,如下所示:

  @Attribute(name = "encodingStyle")
public String encodingStyle;

2).映射其他实体没有前缀:

  @Element(name = "Body")
private AssignedRolesResponseBody responseBody;

@Element(name = "GetAssignedRolesResponse")
private AssignedRolesResponseAction action;

3).映射了 Actionroot:

@Root(name = "u:GetAssignedRolesResponse")
@Namespace(reference = "urn:schemas-upnp-org:service:DeviceProtection:1", prefix = "u")
public class AssignedRolesResponseAction {}

关于android - 无法使用 SimpleXML 反序列化 SOAP 响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41016332/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com