Accepted answer

It's an initialization order problem. You need to define Reads[Hits] before Reads[SearchLikeThisResult]. It compiles because the symbol exists in the code, when when Reads[SearchLikeThisResult] is initialized, Reads[Hits] is not. It goes unnoticed until it attempts to parse the array of Hits, and hits the NPE.

So just swap the order. This is related to this answer.

implicit val hitsReads: Reads[Hits] = (
    (JsPath \ "_index").read[String] and
    (JsPath \ "_type").read[String] and
    (JsPath \ "_id").read[String] and
    (JsPath \ "_score").read[Double]
)(Hits.apply _)

implicit val searchLikeThisResult: Reads[SearchLikeThisResult] = (
    (JsPath \ "total").read[Int] and
    (JsPath \ "max_score").read[Double] and
    (JsPath \ "hits").read[Seq[Hits]]
)(SearchLikeThisResult.apply _)

Related Query

More Query from same tag