让我知道序列化我的Java对象下载的最佳方式。这是一个从WSDL的java wsimport工具生成的类。序列化Java对象
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Download", propOrder = {
"Response",
"VendorInformation",
"DownloadItem",
"DownloadCommentItem",
"DownloadIntercomItem"
})
public class Download
{
@XmlElement(name = "Response")
protected ResponseMessageManagementType Response;
@XmlElement(name = "VendorInformation")
protected DownloadVendorInformation VendorInformation;
@XmlElement(name = "DownloadItem")
protected List<DownloadDownloadItem> DownloadItem;
@XmlElement(name = "DownloadCommentItem")
protected ArrayOfDownloadDldComment DownloadCommentItem;
@XmlElement(name = "DownloadIntercomItem")
protected ArrayOfDownloadDldIntercom DownloadIntercomItem;
.........................
}
该工具生成的java类没有任何serlization实现。 我想要序列化的下载类下面这样的格式:
<?xml version="1.0" encoding="utf-8"?>
<Download xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="HTTP://xyz.abc.Com//Vendor/DownloadWSE.xsd">
<Response>
.....
</Response>
<VendorInformation>
...............
</VendorInformation>
<DownloadItem>
<DownloadDownloadItem>
.......
</DownloadDownloadItem>
<DownloadDownloadItem>
.......
</DownloadDownloadItem>
<DownloadDownloadItem>
.......
</DownloadDownloadItem>
</DownloadItem>
<DownloadCommentItem>
........
</DownloadCommentItem>
<DownloadIntercomItem>
........
</DownloadIntercomItem>
</Download>
你可以看到XmlElementName和XML字符串的内容之间的映射。 我在如何做到这一点的损失。
谢谢
是的。类定义中缺少RootElement。 – user759646 2011-05-19 11:50:54