返回许多内部标签

时间:2018-10-06 16:31:40

标签: java jaxb

我想返回许多内部XML标签payment_response作为响应:

<?xml version="1.0" encoding="UTF-8"?>
<payment_responses page="1" per_page="100" total_count="23" pages_count="1">
    <payment_response>
        <transaction_type>authorize3d</transaction_type>
        <status>pending_async</status>
    </payment_response>
    <payment_response>
        <transaction_type>authorize3d</transaction_type>
        <status>pending_async</status>
    </payment_response>
    <payment_response>
        <transaction_type>authorize3d</transaction_type>
        <status>pending_async</status>
    </payment_response>
</payment_responses>

我尝试过:

XML标签:PaymentResponses

@XmlRootElement(name = "payment_responses")
public class PaymentResponses {

    @XmlElement(name = "payment_response")
    public PaymentResponse paymentResponse;

    @XmlElement(name = "technical_message")
    public String technical_message;

    public PaymentResponses() {
    }

    public PaymentResponses(PaymentResponse paymentResponse) {
        this.paymentResponse = paymentResponse;
    }

    public PaymentResponses(String technical_message) {
        this.technical_message = technical_message;
    }
}

XML标签付款响应:

public class PaymentResponse {

    @XmlElement(name = "transaction_type")
    public String transaction_type;
    @XmlElement(name = "status")
    public String status;

    public PaymentResponse() {
    }   

    public PaymentResponse(String unique_id) {
        this.unique_id = unique_id;
    }

生成响应:

    List<PaymentTransactions> paymentTransactions = ........;

    PaymentResponse dd = null;

    for (int e = 0; e < paymentTransactions.size(); e++) {
        PaymentTransactions res = paymentTransactions.get(e);

        dd = new PaymentResponse(res.getUnique_id());

    }

    PaymentResponses pt = new PaymentResponses(dd);

    return pt;

但是我总是得到:

<?xml version='1.0' encoding='UTF-8'?>
<payment_responses>
    <payment_response>
        <unique_id>01h90ogbevoh5jdwi5ropbw96g02kkxd</unique_id>
    </payment_response>
</payment_responses>

我如何获得许多内部标签?

0 个答案:

没有答案