users@jaxb.java.net

Re: cloning JAXBElements

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 05 Jun 2006 22:43:52 -0700

Alec Swan wrote:
> I need to create a "deep" copy of a JAXBElement which was constructed by
> JAXB during the unmarshalling process. None of the classes generated by
> JAXB implement clone() method from java.lang.Object. The ObjectFactory
> class generated by JAXB didn't provide any API useful for this purpose either.

Right.

There's an RFE filed in the issue tracker about writing a plugin that
would make the generated classes cloneable, but to my knowledge it
hasn't done yet (partly because of the problem of JAXBElement not
implementing cloneable.)

Perhaps one might be able to develop a similar plugin based on Ray's
idea --- the copy constructor.


> However, I noticed that JAXBElement implements Serializable and I could
> potentially use this to implement object cloning by serializing and
> de-serializing the target JAXBElement instance.

Yeah, I think that would be a good work around. There's a global
customization to make all the generated classes serializable.

> What is the right way to clone a JAXBElement instance?

It doesn't exist today. I'm hoping that someone would volunteer to write
a plugin.

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com