title: JAXB: Change name of XML Element from Java code?
body: <p>To set the name of an XML element I use annotations like this:</p>
  
  <pre><code>@XmlElement(name = "customer_id")
  public String getId(){}
  </code></pre>
  
  <p>I have to communicate with two different webservices. One expacts an id element named <code>customer_id</code> but the other expacts the id element to be named <code>id</code>. I solved the problem by creating a second <code>Customer</code> class with the same attributes. The only different is that it uses the following annotation</p>
  
  <pre><code>@XmlElement(name = "id")
  public String getId(){}
  </code></pre>
  
  <p>and it has a copy constructor which copies all attributes from <code>Customer1</code> to <code>Customer2</code>. When I am communicating with the first webservice I send a <code>Customer1</code> object and the other webservice gets a <code>Customer2</code> object. </p>
  
  <p>Is there any possibility to use only one <code>Customer</code> object, but rename the <code>id</code> attribute to whatever the webservice expects? </p>