:xml怎么和java的对象转换呢?有什么方法呢?希望下面的文章对大家有所帮助。
1.xstream解析报文
XStreamComponent x = XStreamComponent.newInstance();
x.processAnnotations(new Class[]{EquityExchangeDetail.class,PearTicketCustomerDTO.class,Date.class,Integer.class});
EquityExchangeDetail ptd = (EquityExchangeDetail) x.fromXML(xml);
2.xstream封装报文
XStreamComponent xres = XStreamComponent.newInstance();
xres.processAnnotations(new Class[]{TransResult.class});
String result=xres.toXML(transResult);
3.
注解:
@XStreamAlias("customerInfo") //报文中
public class PearTicketCustomerDTO {
@XStreamAlias("idno") //报文中
private String idno;
@XStreamOmitField
private Long ticketId; //报文中无
4.方法比较
x.processAnnotations(new Class[]{PearTicketDTO.class}):读取类名注解
x.alias(new Class[]{PearTicketDTO.class}):不读取类名注解
5.解析报文
x.alias("Equities", List.class);--把报文节点
x.alias("Equity", Equity.class);--把报文节点
List
就爱阅读www.92to.com网友整理上传,为您提供最全的知识大全,期待您的分享,转载请注明出处。
来源: