title: Convert Json to scala object
body: <p>I have the following Json string:  </p>
  
  <pre><code>{
    "references": {
      "configuratorId": "conf id",
      "seekId": "seekid",
      "hsId": "hsid",
      "fpId": "fpid"
    }
  }
  </code></pre>
  
  <p>And i want to create an object from it in my Rest API Controller.  </p>
  
  <p>The code:  </p>
  
  <pre><code>case class References(configuratorId: Option[String], seekId: Option[String], hsId: Option[String], fpId: Option[String]) {}
  </code></pre>
  
  <p>The Formatter:  </p>
  
  <pre><code>trait ProductFormats extends ErrorFormats {
    implicit val referencesFormat = Json.format[References]
  
  implicit val referenceFormat = new Format[References]{
  def writes(item: References):JsValue = {
    Json.obj(
        "configuratorId" -&gt; item.configuratorId,
        "seekId" -&gt; item.seekId,
        "hsId" -&gt; item.hsId,
        "fpId" -&gt; item.fpId
        )
  }
  def reads(json: JsValue): JsResult[References] = 
  JsSuccess(new References(
      (json \ "configuratorId").as[Option[String]],
      (json \ "seekId").as[Option[String]],
      (json \ "hsId").as[Option[String]],
      (json \ "fpId").as[Option[String]]
      ))
      }
  </code></pre>
  
  <p>Code in my controller:  </p>
  
  <pre><code>def addProducts(lang: String, t: String) = Action {
    request =&gt;
      request.body.asJson.map {
        json =&gt;
          val req = json.as[References]
          println(req.configuratorId.getOrElse("it was empty !!"))
          Ok(Json.toJson((req)))
      }.getOrElse {
        println("Bad json:" + request.body.asText.getOrElse("No data in body"))
        BadRequest("Incorrect json data")
      }
  }
  </code></pre>
  
  <p>The object is full with null values.. I guess my reads is wrong - but i cant figure out why.  </p>
  
  <p>Thanks!!</p>