(1).先看看XML内容
<postsalescreateResponse
xmlns="http://tempurl.org">
<postsalescreateResult>
<header>
<responsecode>1000</responsecode>
<responsemessage>[A00001-01-PS230925-2566-000009] PostSalesCreate - Sales doc. already exists.[20230925,A00001,01,PS230925-2566-000009]</responsemessage>
</header>
<salestotal>
<txdate_yyyymmdd>20230925</txdate_yyyymmdd>
<txtime_hhmmss>175607</txtime_hhmmss>
</salestotal>
</postsalescreateResult>
</postsalescreateResponse>
(2).查看实体类1:postsalescreateResponse
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "postsalescreateResponse", namespace = "http://tempurl.org", propOrder = {
"postsalescreateResult"
})
public class PostsalescreateResponse {
@XmlElement(name = "postsalescreateResult")
private PostsalescreateResult postsalescreateResult;
--- getTer Or setTer
}
(3).查看实体类2:postsalescreateResult
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "postsalescreateResult", propOrder = {
"header",
"salestotal"
})
public class PostsalescreateResult {
@XmlElement(name = "header")
protected Header header;
@XmlElement(name = "salestotal")
private Salestotal salestotal;
--- getTer Or setTer
}
然后我获取到的PostsalescreateResult节点永远是null,之前通过序列化这样生成xml都是可以的,但是反序列化一直不可以,折腾太久了,最后在Google中查看到1个答案,反序列化的时候xml的命名空间namespace不支持继承,在反序列化的时候必须给每个子节点设置这个命名空间。我们完善下子节点的命名空间即可,例如:
@XmlElement(name = "header", namespace = "http://tempurl.org")
protected Header header;
@XmlElement(name = "salestotal", namespace = "http://tempurl.org")
private Salestotal salestotal;
扫描二维码推送至手机访问。
版权声明:本文由高久峰个人博客发布,如需转载请注明出处。
本文链接:https://blog.20230611.cn/post/647.html