title: How to set different alias for same class elements using XStream
body: <p>How to set different alias for XML elements for same class elements using XStream?</p>
  
  <p>I have the following classes and would like to reuse Phone class to represent both homephone and workphone that would generate XML of the following format</p>
  
  <pre><code>&lt;customer&gt;
    &lt;id&gt;222&lt;/id&gt;
    &lt;name&gt;TestCustomer&lt;/name&gt;
    &lt;workPhone&gt;
      &lt;workPhoneNumber&gt;12345678&lt;/workPhoneNumber&gt;
      &lt;workPhoneExtn&gt;2345&lt;/workPhoneExtn&gt;
    &lt;/workPhone&gt;
    &lt;workPhone&gt;
      &lt;workPhoneNumber&gt;23456789&lt;/workPhoneNumber&gt;
      &lt;workPhoneExtn&gt;2555&lt;/workPhoneExtn&gt;
    &lt;/workPhone&gt;
    &lt;homePhone&gt;
      &lt;homePhoneNumber&gt;222222222&lt;/homePhoneNumber&gt;
      &lt;homePhoneExtn&gt;1234&lt;/homePhoneExtn&gt;
    &lt;/homePhone&gt;
  &lt;/customer&gt;
  </code></pre>
  
  <p>With the following code, I am able to set different alias only till the class level for homephone and workphone objects.</p>
  
  <pre><code>@XStreamAlias("customer")
  public class Customer {
  
      private String id;
      private String name;    
  
      @XStreamImplicit(itemFieldName = "workPhone")
      private ArrayList&lt;Phone&gt; workPhones;
  
      @XStreamImplicit(itemFieldName = "homePhone")
      private ArrayList&lt;Phone&gt; homePhones;
  }
  
  public class Phone {
      private String number;
      private String extn;
  }
  </code></pre>
  
  <p>With the above class definitions, I can only get the following XML structure:</p>
  
  <pre><code>&lt;customer&gt;
    &lt;id&gt;222&lt;/id&gt;
    &lt;name&gt;TestCustomer&lt;/name&gt;
    &lt;workPhone&gt;
      &lt;number&gt;12345678&lt;/number&gt;
      &lt;extn&gt;2345&lt;/extn&gt;
    &lt;/workPhone&gt;
    &lt;workPhone&gt;
      &lt;number&gt;12345678&lt;/number&gt;
      &lt;extn&gt;2355&lt;/extn&gt;
    &lt;/workPhone&gt;
    &lt;homePhone&gt;
      &lt;number&gt;222222222&lt;/number&gt;
      &lt;extn&gt;1234&lt;/extn&gt;
    &lt;/homePhone&gt;
  &lt;/customer&gt;
  </code></pre>
  
  <p>I do not have clear understanding of whether Mappers or converters would help achieve this.</p>
  
  <p>Can someone suggest if there is anyway to set the Phone's number and extension to take the alias "workphoneNumber", "workphoneExtn" / "homePhoneNumber", "homePhoneExtn" depending on the alias for its class? It should both work during marshalling and unmarshalling. Please suggest.</p>