title: Java/JAXB: Unmarshall Xml to specific subclass based on an attribute
body: <p>Is it possible to use JAXB to unmarshall xml to a specific Java class based on an attribute of the xml?</p>
  
  <pre><code>&lt;shapes&gt;
    &lt;shape type="square" points="4" square-specific-attribute="foo" /&gt;
    &lt;shape type="triangle" points="3" triangle-specific-attribute="bar" /&gt;
  &lt;/shapes&gt;
  </code></pre>
  
  <p>I would like to have a List of Shape objects containing a triangle and a square, each with their own shape-specific attribute. IE:</p>
  
  <pre><code>abstract class Shape {
      int points;
      //...etc
  }
  
  class Square extends Shape {
      String square-specific-attribute;
      //...etc
  }
  
  class Triangle extends Shape {
      String triangle-specific-attribute;
      //...etc
  }
  </code></pre>
  
  <p>I'm currently just putting all attributes in one big "Shape" class and it's less than ideal.</p>
  
  <p>I could get this to work if the shapes were properly named xml elements, but unfortunately I don't have control of the xml I'm retrieving.</p>
  
  <p>Thanks!</p>