title: Deserialize nested polymorphic json field with json4s
body: <p>I have a common problem but still couldn't wrap my head around what I was reading around.</p>
  
  <p>In a scalatra app, I am receiving the following json:</p>
  
  <pre><code>{
  _type: "hello",
  timestamp: 123,
  data: [
  {table: "stuffJ",_id: 24},
  {table: "preferences",_id: 34,word: "john"}
  ]}
  </code></pre>
  
  <p>with an unknown number of elements in field 'data'. The field table will always be there to differentiate between class types. I am trying to have it parsed to class <code>RestAPIMessage</code>. This is what I have so far:</p>
  
  <pre><code>    implicit val jsonFormats = new DefaultFormats { outer =&gt;
          override val typeHintFieldName = "table"
          override val typeHints = ShortTypeHints(List(classOf[Preferences], classOf[StuffJ]))
        }
  
      sealed trait DataJson 
      case class Preferences(table: String, _id: Long, word : String) extends DataJson
      case class StuffJ(table: String, _id: Long) extends DataJson
      case class RestAPIMessage(_type: String, timestamp: Long, data: List[DataJson])
  
      // if sent as Json, returns a json with two "table" fields
      val message = new RestAPIMessage("hello", 123, List(new StuffJ("StuffJ", 24), new Preferences("preferences", 34, "john"))) 
  
      // if received as Json, fails with a "no usable value for outer" 
      val djson = """{"_type":"hello","timestamp":123,"data":[{"table":"StuffJ","_id":24},{"table":"table":"preferences","_id":34,"word":"john"}]}"""
  </code></pre>
  
  <p>Thanks for your help!</p>