title: Jersey, JAXB and getting an object extending an abstract class as a parameter
body: <p>I want to get an object as a parameter of a POST request. I got an abstract superclass that is called <code>Promotion</code> and subclasses <code>Product</code> and <code>Percent</code>. Here's how I try to get a request:</p>
  
  <pre><code>@POST
  @Consumes(MediaType.APPLICATION_XML)
  @Produces(MediaType.APPLICATION_XML)
  @Path("promotion/")
  public Promotion createPromotion(Promotion promotion) {         
      Product p = (Product) promotion;
      System.out.println(p.getPriceAfter());      
  
      return promotion;
  }
  </code></pre>
  
  <p>and here's how I use JAXB in classes' definitions:</p>
  
  <pre><code>@XmlRootElement(name="promotion")
  @XmlSeeAlso({Product.class,Percent.class})
  public abstract class Promotion {
      //body
  }
  
  
  @XmlRootElement(name="promotion")
  public class Product extends Promotion {
      //body
  }
  
  
  @XmlRootElement(name="promotion")
  public class Percent extends Promotion {
      //body
  }
  </code></pre>
  
  <p>So the problem now is when I send a POST request with a body like this:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;promotion&gt;
    &lt;priceBefore&gt;34.5&lt;/priceBefore&gt;
    &lt;marked&gt;false&lt;/marked&gt;
    &lt;distance&gt;44&lt;/distance&gt;
  &lt;/promotion&gt;
  </code></pre>
  
  <p>and I try to cast it to Product (as in this case, fields 'marked' and 'distance' are from Promotion class and 'priceBefore' is from Product class) I get an Exception:</p>
  
  <pre><code>java.lang.ClassCastException: Percent cannot be cast to Product. 
  </code></pre>
  
  <p>It seems like <code>Percent</code> is chosen as a 'default' subclass. Why is that and how can I get an object that is a <code>Product</code>?</p>