JAXB:XML-Object转换(复杂类型,对象包含对象)

CupMobiles.java:

package com.sitech.echn.uupay.model;

import javax.xml.bind.annotation.XmlRootElement;
/**
 * xml对应的java模型
 * @author wangyfc
 *
 */
@XmlRootElement
public class CupMobiles {
	private CupMobile cupMobile;
	private String msgResponseCode;
	public CupMobile getCupMobile() {
		return cupMobile;
	}
	public void setCupMobile(CupMobile cupMobile) {
		this.cupMobile = cupMobile;
	}
	public String getMsgResponseCode() {
		return msgResponseCode;
	}
	public void setMsgResponseCode(String msgResponseCode) {
		this.msgResponseCode = msgResponseCode;
	}
	
}

 

package com.sitech.echn.uupay.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class CupMobile {
 @XmlAttribute
 private String application="UPNoCard";
 @XmlAttribute
 private String version="1.01";
 private Transaction transaction;
public String getApplication() {
	return application;
}
public void setApplication(String application) {
	this.application = application;
}
public String getVersion() {
	return version;
}
public void setVersion(String version) {
	this.version = version;
}
public Transaction getTransaction() {
	return transaction;
}
public void setTransaction(Transaction transaction) {
	this.transaction = transaction;
}
}

 

package com.sitech.echn.uupay.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Transaction {
@XmlAttribute
private String type="Purchase.PMReq";
private String submitTime;
private Order order;
private Merchant merchant;
private String accountNumber1;
private String transSerialNumber;
private String transResponseCode;
private String billAmount;
private String settleDate;
public String getType() {
	return type;
}
public void setType(String type) {
	this.type = type;
}
public String getSubmitTime() {
	return submitTime;
}
public void setSubmitTime(String submitTime) {
	this.submitTime = submitTime;
}
public Order getOrder() {
	return order;
}
public void setOrder(Order order) {
	this.order = order;
}
public Merchant getMerchant() {
	return merchant;
}
public void setMerchant(Merchant merchant) {
	this.merchant = merchant;
}
public String getAccountNumber1() {
	return accountNumber1;
}
public void setAccountNumber1(String accountNumber1) {
	this.accountNumber1 = accountNumber1;
}
public String getTransSerialNumber() {
	return transSerialNumber;
}
public void setTransSerialNumber(String transSerialNumber) {
	this.transSerialNumber = transSerialNumber;
}
public String getBillAmount() {
	return billAmount;
}
public void setBillAmount(String billAmount) {
	this.billAmount = billAmount;
}
public String getSettleDate() {
	return settleDate;
}
public void setSettleDate(String settleDate) {
	this.settleDate = settleDate;
}
public String getTransResponseCode() {
	return transResponseCode;
}
public void setTransResponseCode(String transResponseCode) {
	this.transResponseCode = transResponseCode;
}

}

 

package com.sitech.echn.uupay.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Merchant {
	@XmlAttribute
	private String id;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
}

 

package com.sitech.echn.uupay.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Order {
@XmlAttribute
private String id;

public String getId() {
	return id;
}

public void setId(String id) {
	this.id = id;
}
}

 

<?xml version="1.0" encoding="UTF-8"?>
<cupMobiles>
	<cupMobile application="UPNoCard" version="1.01">
		<transaction type="Purchase.MPRsp">
			<submitTime>20111207111641</submitTime>
			<order id="12347733"/>
			<merchant id="303290047228001"/>
			<accountNumber1>6224130665233518</accountNumber1>
			<transSerialNumber>201162</transSerialNumber>
			<transRresponseCode>00000</transRresponseCode>
			<billAmount currency="156">000000030231</billAmount>
			<settleDate>20111208</settleDate>
		</transaction>
	</cupMobile>
	<msgResponseCode>000000</msgResponseCode>
</cupMobiles>

 

你可能感兴趣的:(object)