users@jaxb.java.net

RE: cloning JAXBElements

From: ray lukas <ray_lukas_at_comcast.net>
Date: Sun, 4 Jun 2006 20:04:15 -0400

Well I do not know your code, so this may be of no help. Hopefully it will
not be an aggravation to you but.. I tend to shy away from the cloneable
contract. That JAXB element you are referring to, at least in my systems, is
really one of my objects that I am using JAXB to bring into existence from
an XML file. Since that is the case I, like you, need to sometimes need to
make copies of it. Both deep copies and shallow ones. Instead of using Clone
I use simple copy constructors into which I pass a Boolean called, you
probably guessed, deepCopy.

This allows me to avoid the cloneable contract and the ramifications of that
(side effects).. I do not know if this helps you at all. But perhaps a
different way of thinking on the subject might be in order.. Did you, or
better said, can you consider the using of copy constructors instead of
clone.

 

Once again I do not have your code in front of me and have little to go on
expect for personal experience. Which I am sharing..

ray

  _____

From: Alec Swan [mailto:aukcioner_at_yahoo.com]
Sent: Sunday, June 04, 2006 7:41 PM
To: users_at_jaxb.dev.java.net
Subject: cloning JAXBElements

 

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.

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.

What is the right way to clone a JAXBElement instance?

Thanks.

Alec