【发布时间】:2015-05-23 16:45:42
【问题描述】:
我使用xstream从java对象生成xml,下面是java对象生成的xml
<brokermail>
<invoiceReferenceNotificationMessage>
<com.absfm.ice.ioa.jms.InvoiceReferenceNotificationMessage>
<InvoiceReference>SM/829709/0315</InvoiceReference>
<ABSReference>IRMAR157311</ABSReference>
<Currency>GBP</Currency>
<InvoiceAmount>2546.0</InvoiceAmount>
<PaidAmount>1245.0</PaidAmount>
<BalanceAmount>0.0</BalanceAmount>
<ValueDate>2015-05-23 20:07:20.78 IST</ValueDate>
<Remarks>abc</Remarks>
</com.rbsfm.ice.ioa.jms.InvoiceReferenceNotificationMessage>
<com.rbsfm.ice.ioa.jms.InvoiceReferenceNotificationMessage>
<InvoiceReference>SM/15</InvoiceReference>
<ABSReference>I157311</ABSReference>
<Currency>EUR</Currency>
<InvoiceAmount>255546.0</InvoiceAmount>
<PaidAmount>125545.0</PaidAmount>
<BalanceAmount>0.0</BalanceAmount>
<ValueDate>2015-05-23 20:07:20.78 IST</ValueDate>
<Remarks>abERRc</Remarks>
</com.absfm.ice.ioa.jms.InvoiceReferenceNotificationMessage>
</invoiceReferenceNotificationMessage>
</brokermail>
但我希望以下面的方式生成 xml
<brokermail>
<invoiceReferenceNotificationMessage>
<InvoiceReference>SM/829709/0315</InvoiceReference>
<ABSReference>IRMAR157311</ABSReference>
<Currency>GBP</Currency>
<InvoiceAmount>2546.0</InvoiceAmount>
<PaidAmount>1245.0</PaidAmount>
<BalanceAmount>0.0</BalanceAmount>
<ValueDate>2015-05-23 20:38:35.110 IST</ValueDate>
<Remarks>abc</Remarks>
</invoiceReferenceNotificationMessage>
<invoiceReferenceNotificationMessage>
<InvoiceReference>SM/15</InvoiceReference>
<ABSReference>I157311</ABSReference>
<Currency>EUR</Currency>
<InvoiceAmount>255546.0</InvoiceAmount>
<PaidAmount>125545.0</PaidAmount>
<BalanceAmount>0.0</BalanceAmount>
<ValueDate>2015-05-23 20:38:35.110 IST</ValueDate>
<Remarks>abERRc</Remarks>
</invoiceReferenceNotificationMessage>
</brokermail>
现在如上所示,我希望以上述方式生成 xml,但现在还没有发生。您能否告知我需要在下面的 pojo 中进行哪些更改才能以上述方式获取 xml。下面是我的pojo
public class Mail {
private List<InvoiceReferenceNotificationMessage> invoiceReferenceNotificationMessage = new ArrayList<InvoiceReferenceNotificationMessage>();
public List<InvoiceReferenceNotificationMessage> getInvoiceReferenceNotificationMessages() {
return invoiceReferenceNotificationMessage;
}
public void addInvoiceReferenceNotificationMessages(List<InvoiceReferenceNotificationMessage> invoiceReferenceNotificationMessages) {
this.invoiceReferenceNotificationMessage = invoiceReferenceNotificationMessages;
}
}
这是正在发生的主要方法调用
下面是xstream用来生成xml的主类。
InvoiceReferenceNotificationMessage invoiceReferenceNotificationMessage = new InvoiceReferenceNotificationMessage();
invoiceReferenceNotificationMessage.setInvoiceReference("SM/854565");
invoiceReferenceNotificationMessage.ABSReference("IRM5454311");
invoiceReferenceNotificationMessage.setCurrency("GBP");
invoiceReferenceNotificationMessage.setInvoiceAmount(255446);
invoiceReferenceNotificationMessage.setPaidAmount(12445);
invoiceReferenceNotificationMessage.setBalanceAmount(0);
invoiceReferenceNotificationMessage.setValueDate(new Date());
invoiceReferenceNotificationMessage.setRemarks("abc");
InvoiceReferenceNotificationMessage invoiceReferenceNotificationMessage1 = new InvoiceReferenceNotificationMessage();
invoiceReferenceNotificationMessage1.setInvoiceReference("SM/14545");
invoiceReferenceNotificationMessage1.ABSReference("I15745311");
invoiceReferenceNotificationMessage1.setCurrency("EUR");
invoiceReferenceNotificationMessage1.setInvoiceAmount(2555546);
invoiceReferenceNotificationMessage1.setPaidAmount(125545);
invoiceReferenceNotificationMessage1.setBalanceAmount(0);
invoiceReferenceNotificationMessage1.setValueDate(new Date());
invoiceReferenceNotificationMessage1.setRemarks("abERRc");
List<InvoiceReferenceNotificationMessage> invoiceReferenceNotificationMessagest = new ArrayList<InvoiceReferenceNotificationMessage>();
invoiceReferenceNotificationMessagest.add(invoiceReferenceNotificationMessage);
invoiceReferenceNotificationMessagest.add(invoiceReferenceNotificationMessage1);
Mail m = new Mail();
m.addInvoiceReferenceNotificationMessages(invoiceReferenceNotificationMessagest);
XStream xstream = new XStream();
xstream.alias("brokermail",Mail.class);
String abc = xstream.toXML(m);
System.out.println(abc);
请告知我需要在上面的 pojos 中进行哪些更改才能获得所需的 xml,如我所示 伙计们,请为此提供建议,任何早期帮助将不胜感激提前谢谢
【问题讨论】:
标签: java