如何克隆JAXB对象 [英] How Do I Clone A JAXB Object
问题描述
我需要克隆一些jaxb对象(从jsb生成的xsd代码实例化)。 Jaxb类似乎没有为这样做提供简单的界面。我无法手动编辑类并且无法扩展它 - 因此我需要创建一个帮助器/实用程序方法来执行此操作。什么是最好的方法?
I have some jaxb objects (instantiated from code generated from xsd by jaxb) that I need to clone. The Jaxb class does not appear to provide an interface for doing this easily. I can not hand edit the class and can not extend it - so I need to create a helper/utility method to do this. What is the best approach?
推荐答案
鉴于JAXB的目的,我认为最简单的方法是将对象编组为XML并解散它。
Given the purpose of JAXB, I think the easiest way would be to marshall your object to XML and unmarshall it back.
关于 Google 。
JAXB FAQ suggests beanlib.
还有一些讨论(以及下载的链接) jaxb2-commons下的Cloneable插件,虽然我在项目页面上找不到任何引用。
There's also some discussion (as well as a link to download) of a Cloneable plugin under jaxb2-commons, although I can't find any reference on the project page.
这篇关于如何克隆JAXB对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!