title: Play Json - Complex object creation
body: <p>I'm trying to create Json readers in my Play framework application (Scala). The problem is, part of my Json is a little funky, and requires further processing to retrieve the values. For example:</p>
  
  <pre><code>{  
    "field1":"value1",
    "field2":"value/1",
    "num2":2
  }
  </code></pre>
  
  <p>with case classes:</p>
  
  <pre><code>case class Field1(text: String, fields: Field2)
  case class Field2(text: String, num: Int, num2: Int)
  </code></pre>
  
  <p>Basically the <code>text</code> and <code>num</code> fields for <code>Field2</code> are derived from the value <code>value/1</code>, by splitting the text. Here's the splitter function:</p>
  
  <pre><code>def splitter(path: String, num2: Int): Field2 = {
    val split = path.split("\\")
    Field2(split(0), split(1).toInt, num2)
  }
  </code></pre>
  
  <p>This is fairly straightforward, the actual splitter function is far more complex. Basically the only way to construct this object <code>Field2</code> is to pass a single string to a function that spits out the required object.</p>
  
  <p>How do I go about creating a reader for <code>Field2</code> (and by extension for <code>Field1</code>)?</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>object Field1 {
      implicit val reader = (
          (__ \ "field1").read[String] and
          (__).read[Field2]
      ) (Field1.apply _)
  }
  
  object Field2 {
      implicit val reader = (
          splitter((__ \ "field2").read[String], (__ \ "num2"))
      ) // Obviously incorrect syntax + type mismatch, but this is roughly what I'm trying to accomplish.
  }
  </code></pre>