Castor 1.2 用于 POJO 到 XML
我使用 Castor 1.2 进行编组。
您有使用 Castor 实现此目的的经验吗?
您对提高性能有什么建议吗?
I am using Castor 1.2 for marshalling.
Do you have any experience with using Castor for this purpose?
Do you have suggestions for improving performance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Castor 1.2 是最后一个提供对 Java 1.4 支持的版本,因此它仍然被尚未过渡到 1.5 或 1.6 的商店广泛使用(就我而言,我们只能部署到较旧的 Weblogic 版本)。
获得性能改进的最佳方法是使用映射文件,而不是让 Castor 使用反射来编组/解组 XML。 映射文件可以包含显式 XML 元素到 Java 类映射,并省略您不感兴趣的任何翻译。因此,例如,如果 XML 记录包含客户的账单信息以及最近 100 个订单的历史记录,但您所有的关心的是计费信息,您可以显式地将适当的 XML 元素映射到您的计费信息类。 Castor 将忽略其余的 XML 元素,从而加快编组过程。
最后的提示是下载 Castor 1.2 的源代码,即使您不打算自己构建代码。 1.2 的文档尚未保持最新,因此一些看似在 1.3 及更高版本中引入的新功能实际上也已添加到 Castor 1.2 中。 快速比较 1.3 文档和 1.2 代码将让您了解 Castor 1.2 最近做了哪些改进。
Castor 1.2 was the last version to provide support for Java 1.4, so it's still widely used by shops that haven't made the transition to 1.5 or 1.6 (in my case, we're stuck with deploying to an older Weblogic version).
The best way to gain performance improvements is to use a mapping file, rather than having Castor use reflection to marshall/unmarshall your XML. The mapping file can contain explicit XML element to Java class mappings, and omit any translations you are not interested in. So, for example, if an XML record contains a customer's billing information along with a history of the last 100 orders, but all you care about is the billing information, you can explicitly map the appropriate XML elements to your billing information classes. Castor will ignore the remainder of the XML elements, speeding up the marshalling process.
A final tip is to download the source code for Castor 1.2, even if you don't plan on building the code yourself. The documentation for 1.2 hasn't been kept up to date, so some new features that appear to have been introduced in 1.3 and higher have actually been added to Castor 1.2 as well. A quick comparison of the 1.3 documentation and 1.2 code will let you see what improvements have been recently made to Castor 1.2.