Deep copy without package names
<p>How can I deep copy the same objects from different packages, but with the same structure without serialization?</p>

<p>Example:</p>

<pre><code>package com.foo;
class Tree{
    List&lt;Leaf&gt; leaf;
    Int trunk;
}
</code></pre>

<p>and</p>

<pre><code>package com.bar;
class Tree{
    List&lt;Leaf&gt; leaf;
    Int trunk;
}
</code></pre>

<p>both with more complex sub-objects (ArrayLists of ArrayLists).
This is basically the same object that I receive via different webservices and is therefore in different packages. </p>

<p>I would like to be able to "map" all different version to the same object, e.g.</p>

<p>Casting: <code>com.bar.Tree barTree = (com.foo.Tree) fooTree;</code></p>

<p>or deep copy: <code>com.bar.Tree barTree = DeepCopy.(fooTree);</code></p>

<p>With the expected result that <code>barTree.leaf[k] == fooTree.leaf[k]</code> and <code>barTree.trunk==fooTree.trunk</code>.</p>

<p>I could theoretically recursively copy all calues via reflection to the corresponding elements (with the same name) of the other object, but isn't there an easier way?</p>

<p>Edit: More complex example.</p>