title: How to convert a json with a single value to a case class using play json
body: <p>I have problems to find how to convert a json doc with a single value to a case class. Here is the json:</p>
  
  <pre><code>{
    "ax" : {
             "bx" : "value1",
             "by" : "value2
           }
  }
  </code></pre>
  
  <p>Here are the case classes:</p>
  
  <pre><code>case class B(bx: String, by: String)
  case class A(ax: B)
  </code></pre>
  
  <p>And here are the reads:</p>
  
  <pre><code>import play.api.libs.json._
  import play.api.libs.json.Reads._
  import play.api.libs.functional.syntax._
  
  object Implicits {
       implicit val bReads: Reads[B] = (
          ( __ \ "bx" ).read[String] ~
          ( __ \ "by" ).read[String]
       ) ( B.apply _ )    
  
       implicit val aReads: Reads[A] = (
          ( __ \ "ax" ).read[B]
       ) ( A.apply _ )
  }
  </code></pre>
  
  <p>The second implicit doesn't compile with the following error:</p>
  
  <pre><code>Error:(X, Y) overloaded method value read with alternatives:
  (t: B)play.api.libs.json.Reads[B] &lt;and&gt;
  (implicit r: play.api.libs.json.Reads[B])play.api.libs.json.Reads[B]
  cannot be applied to ((B, Option[String]) =&gt; A)
     ( __ \ "ax" ).read[B] 
  </code></pre>
  
  <p>In order to make it work, I need to change the A class to have another value:</p>
  
  <pre><code>case class A(ax: B, temp: Option[String])
  </code></pre>
  
  <p>And the implicit read:</p>
  
  <pre><code>implicit val aReads: Reads[A] = (
     ( __ \ "ax" ).read[B] ~
     ( __ \ "temp" ).readNullable[String]
  ) ( A.apply _ )
  </code></pre>
  
  <p>How the reads can be done without having to add something that doesn't exists to the classes? Any ideas?</p>