Saturday, June 18, 2005
Generic Deep Clone via XStream
One common technique to implement generic deep clone is to take advantage of Java Serialization. The trick is simply to serialize/deserialize the object graph. However, this has the limitation that it only works for the portions of an object graph that implement Serializable.
To remove this constraint, we can apply similar technique with XStream, which doesn't require a class to implement Serializable for serializing deeply to/from XML. The deep clone would then work for all classes. (Note XStream does not serialize transient fields.)
To remove this constraint, we can apply similar technique with XStream, which doesn't require a class to implement Serializable for serializing deeply to/from XML. The deep clone would then work for all classes. (Note XStream does not serialize transient fields.)
Comments:
<< Home
I noticed in the XSTREAM examples that the instance data was not in CDATA. Does this mean that xml etc are not serlialised properly, or is this done on an 'as needs' basis?
Just try and see :). If you set some XML fragments into the value of a bean property, XStream would escape the "offending" characters using entity/character references.
For example,
"<product3<name>>" ==>
"<product3<name>>"
Post a Comment
For example,
"<product3<name>>" ==>
"<product3<name>>"
<< Home