title: Java complex validation in Dropwizard?
body: <p>I'd like to accept JSON on an REST endpoint and convert it to the correct type for immediate validation.</p>
  
  <p>The endpoint looks like this:</p>
  
  <pre><code>@POST
  public Response createCar(@Valid Car car) { 
      // persist to DB
      // ... 
  }
  </code></pre>
  
  <p>But there are many subclasses of Car, e.g. Van, SelfDrivingCar, RaceCar, etc. How could I accept the different JSON representations on the endpoint, while keeping the validation code
  in the Resource as concise as something like <code>@Valid Car car</code>?</p>
  
  <p>Again: I send in JSON like (here, it's the representation of a subclass of Car, namely SelfDrivingCar):</p>
  
  <pre><code>{ 
      "id" : "t1",                      // every Car has an Id
      "kind" : "selfdriving",           // every Car has a type-hint
      "max_speed" : "200 mph",          // some attribute
      "ai_provider" : "fastcarsai ltd." // this is SelfDrivingCar-specific
  }
  </code></pre>
  
  <p>and I'd like the validation machinery look into the <code>kind</code> attribute, create an instance of the appropriate subclass, here e.g. <code>SelfDrivingCar</code> and perform validation.</p>
  
  <p>I know I could create different endpoints for all kind of cars, but thats does not seem DRY. And I know that I could use a real <code>Validator</code> instead of the annotation and do it by hand, so I'm just asking if there's some elegant shortcut for this problem.</p>