我使用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 {
@SuppressWarnings("unused")
private List<InvoiceReferenceNotificationMessage> invoiceReferenceNotificationMessage;
@XStreamImplicit(itemFieldName="invoiceReferenceNotificationMessage")
private List<InvoiceReferenceNotificationMessage> InvoiceReferenceNotificationMessage =
new ArrayList<InvoiceReferenceNotificationMessage>();
public List<InvoiceReferenceNotificationMessage> getInvoiceReferenceNotificationMessages() {
return InvoiceReferenceNotificationMessage;
}
public void addInvoiceReferenceNotificationMessages(List<InvoiceReferenceNotificationMessage> invoiceReferenceNotificationMessages) {
this.invoiceReferenceNotificationMessage = invoiceReferenceNotificationMessages;
}
}
这是正在发生的主要方法调用
下面是使用xstream以下生成xml的主要类。
ist<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);
xstream.processAnnotations(Mail.class);
String abc = xstream.toXML(m);
System.out.println(abc);
现在在xstream.processAnnotations(Mail.class);代码行我得到恭维问题indiacating添加演员到xsteam请告知如何克服这个
the complation error that i am getting that method processAnnotations(class<Mail>) is undefined for the type Xstream
伙计们请为此提供建议
答案 0 :(得分:0)
确保您使用的是最新版本的xstream。 processAnnotations
方法在1.3
如果使用maven,请尝试
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.8</version>
</dependency>