I get a Json feed back from a remote third party API in this way:
val myjson: Future[HttpResponse] = http.singleRequest(HttpRequest(uri = encodedUri))
myjson onComplete {
case Success(response) => sender ! WrappedResponse(response.entity.toJson)
case Failure...
}
case class WrappedResponse(response: JsValue)
The HttpResponse.entity
contains my json feed. Is it possible marshall and unmarshall this Json feed or only parts of it?
One of the problem is that when I send it back wrapped the json in a case class I get something:
Error:(38, 78) Cannot find JsonWriter or JsonFormat type class for akka.http.scaladsl.model.ResponseEntity
case Success(response) => sender ! WrappedResponse(response.entity.toJson)
How can I "marshall" Json itself?
UPDATE
I finally get to unmarshall the data first in this way:
val responseData = sendHttpRequest(encodedUrl)
val bodyAsString = responseData.flatMap { response => Unmarshal(response.entity).to[String] }
bodyAsString onComplete {
case Success(body) => sender ! WrappedResponse(body)
case Failure(response) => response
}
and in my marshaller:
trait MyJsonMarshaller extends SprayJsonSupport with DefaultJsonProtocol {
implicit val titleDeedResponseFormat = jsonFormat1(WrappedResponse.apply)
}
but the "re-apply" marshalling is not working