编程语言
首页 > 编程语言> > 使用XStream实现Java对象与XML互相转换

使用XStream实现Java对象与XML互相转换

作者:互联网

1.需求对接第三方 http post请求 请求报文中message字段 是xml格式;接口返回信息也是xml

  1.1 请求xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<com.ctc.ema.server.jwsserver.sms.MtMessage>
<content>sms test</content>
<phoneNumber>15001710000</phoneNumber>
<phoneNumber>15001710008</phoneNumber>
<phoneNumber>15001710009</phoneNumber>
<sendTime>2013-05-16 13:38:19</sendTime>
<smsId>4acadda1-5806-4492-9a82-b7ab3f1c8ec0</smsId><subCode></subCode>
</com.ctc.ema.server.jwsserver.sms.MtMessage>

  1.2 返回xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<com.ctc.ema.server.jwsserver.sms.MtMessageRes>
<resDetail>
<phoneNumber>15001710000</phoneNumber>
<stat>r:000</stat>
<statDes>提交成功</statDes>
</resDetail>
<resDetail>
<phoneNumber>15001710008</phoneNumber>
<stat>r:000</stat>
<statDes>提交成功</statDes>
</resDetail>
<resDetail>
<phoneNumber>15001710009</phoneNumber>
<stat>r:000</stat>
<statDes>提交成功</statDes>
</resDetail>
<smsId>4acadda1-5806-4492-9a82-b7ab3f1c8ec0</smsId><subStat>r:000</subStat>
<subStatDes>处理成功</subStatDes>
</com.ctc.ema.server.jwsserver.sms.MtMessageRes>

2.尝试使用 Xstream的方式 将java对象与xml进行相互转换

 

 

TRANSLATE with x English
Arabic Hebrew Polish
Bulgarian Hindi Portuguese
Catalan Hmong Daw Romanian
Chinese Simplified Hungarian Russian
Chinese Traditional Indonesian Slovak
Czech Italian Slovenian
Danish Japanese Spanish
Dutch Klingon Swedish
English Korean Thai
Estonian Latvian Turkish
Finnish Lithuanian Ukrainian
French Malay Urdu
German Maltese Vietnamese
Greek Norwegian Welsh
Haitian Creole Persian  
  TRANSLATE with COPY THE URL BELOW Back EMBED THE SNIPPET BELOW IN YOUR SITE Enable collaborative features and customize widget: Bing Webmaster Portal Back

标签:XML,xml,TRANSLATE,Java,XStream,000,location,9a82,document
来源: https://www.cnblogs.com/nextgg/p/16075730.html