title: How to marshal different response types in spray?
body: <p>Consider an http service that can return two json as response:</p>
  
  <p>successful</p>
  
  <pre><code>{
      "yourField":"value"
  }
  </code></pre>
  
  <p>failure</p>
  
  <pre><code>{
      "errorCode": 3
  }
  </code></pre>
  
  <p>To deal with these json's I need to create 2 case classes <code>case class RespSucc(yourField:String)</code> and
  <code>case class RespFail(errorCode:Int)</code>.</p>
  
  <p>For now I have to to something like that:</p>
  
  <pre><code>//unmarshal is spray.httpx.ResponseTransformation#unmarshal
  if (response.entity.asString.contains("errorCode")) {
      unmarshal[RespSucc].apply(response)
  }
  else {
      unmarshal[RespFail].apply(response)
  }
  </code></pre>
  
  <p>Is there an api to parse these classes automatically without any <code>if</code>? E.g. can unmarshaller looks into json fields and select approriate case class?</p>