json - Cannot check and handle null value using Play and Scala -
json - Cannot check and handle null value using Play and Scala -
i trying build api endpoint test using scala , play framework.
the code results in error unable verify if response.json empty. particular endpoint not homecoming , need check such case.
protected def apiresponse[t](response: response)(implicit reads: reads[t]): jsresult[t] = { response.status match { case success(code) => json.fromjson[t](response.json) case clienterror(code) => throw apierror(response.body, response.status) case _ => throw apierror(response.statustext, response.status) } }
i trying of sort.
protected def apiresponse[t](response: response)(implicit reads: reads[t]): jsresult[t] = { response.status match { case success(code) => 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) => throw apierror(response.body, response.status) case _ => throw apierror(response.statustext, response.status) } }
any help appreciated
i figured out how done. realized endpoint returned empty response.body.
if(response.body.tostring == "") did trick me instead of considering value of entire response.json.
please allow me know case has improve way.
json api scala playframework-2.0 automated-tests
Comments
Post a Comment