title: Cannot check and handle null value using Play and Scala
body: <p>I am trying to build an API endpoint test using Scala and the Play framework.</p>
  
  <p>The code results in an error as I am unable to verify if the response.json is empty. This particular endpoint does not return anything and I need check for such a case.</p>
  
  <pre><code>  protected def apiResponse[T](response: Response)(implicit reads: Reads[T]): JsResult[T] = {
      response.status match {
        case Success(code)  =&gt; Json.fromJson[T](response.json)
        case ClientError(code) =&gt; throw ApiError(response.body, response.status)
        case _ =&gt;  throw ApiError(response.statusText, response.status)
      }
    }
  </code></pre>
  
  <p>I am trying to do something of this sort.</p>
  
  <pre><code>protected def apiResponse[T](response: Response)(implicit reads: Reads[T]): JsResult[T] = {
      response.status match {
        case Success(code)  =&gt; if(Json.fromJson[T](response.json).equals(JsNull)) Json.fromJson[T](JsString(response.statusText.toString+"1")) else Json.fromJson[T](response.json)
        case ClientError(code) =&gt; throw ApiError(response.body, response.status)
        case _ =&gt;  throw ApiError(response.statusText, response.status)
      }
    }
  </code></pre>
  
  <p>Any help would be appreciated</p>