I'm using json4s
for dealing with Json responses from http responses. I was earlier using Await
but I'm now switching to use Future
.
I have a function like:
executeRequest(): Future[Response[String]]
and another function like:
def getAccessToken() = {
executeRequest().map {
response: Response[String] => // read method in the next line cannot be resolved
read[AccessTokenResponse](response.body).access_token
}
// the following line is ok
read[AccessTokenResponse]("{\"access_token\":\"fake_token\"}").access_token
}
Now, the read
inside the map
block is no longer recognized/found by my IntelliJ which I'm assuming means I'm doing something wrong. But the read
outside of the map
block resolves correctly.
What am I doing incorrectly here? I'm new to Scala :/
Compiler output:
overloaded method value read with alternatives:
(in: java.io.Reader)(implicit formats: org.json4s.Formats, implicit mf: scala.reflect.Manifest[AccessTokenResponse])AccessTokenResponse <and>
(json: org.json4s.JsonInput)(implicit formats: org.json4s.Formats, implicit mf: scala.reflect.Manifest[AccessTokenResponse])AccessTokenResponse <and>
(json: String)(implicit formats: org.json4s.Formats, implicit mf: scala.reflect.Manifest[AccessTokenResponse])AccessTokenResponse
cannot be applied to (Either[String,String])
read[AccessTokenResponse](response.body).access_token