I'm trying to retrieve some data from a local server through akka library in Scala. Data are returned from server in JSON format, but I'm unable to unmarshall them in a custom type.
Custom class is Profiles, that contains a list of Profiles.
case class Profile(
Name: String,
Surname: String,
Mail: String,
Age: Int,
Town: String,
Role: String,
PrimaryInstr: String,
SecondaryInstr: String,
PrimaryGenre: String,
SecondaryGenre: String,
Influences: String,
RecordLabel: String,
GigAvailability: String,
RehearseAvailability: String,
RecordingExperience: String,
MusicalAge: Int)
case class Profiles(profiles: Vector[Profile])
I've tried with the following code to unmarshall to Profiles, but it does not compile because of the error
could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.Unmarshaller[ResponseEntity, Profiles]
import akka.http.scaladsl.Http
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.http.scaladsl.client.RequestBuilding.Get
import akka.http.scaladsl.model.HttpResponse
...
def getProfiles = {
var req = Get("http://localhost:9090/profiles")
val responseFuture: Future[HttpResponse] = Http().singleRequest(req)
responseFuture
.onComplete {
case Success(response) =>
println(response.entity)
//Here I want actually Unmarshall to Profiles, not to String
var responseAsString = Unmarshal(response.entity).to[String] //Tried here with Profiles
println(responseAsString)
case Failure(_) => sys.error("something wrong")
}
...
}
Unmarshalling with [String] the code produces this output (abbreviated with "...").
HttpEntity.Strict(application/json,[{"Name":"Amadeus","Surname":"Rapisarda", ..., "MusicalAge":9},{"Name":"Federico","Surname":"D'Ambrosio", ..., "MusicalAge":24}]) FulfilledFuture([{"Name":"Amadeus","Surname":"Rapisarda", ..., "MusicalAge":9},{"Name":"Federico","Surname":"D'Ambrosio", ..., "MusicalAge":24}])
How I could obtain a Profiles object? Thanks in advance!