I'm trying to unmarshal a json response from a REST service into a Java pojo but am unable to do so.
- How do I get the response body out of
HttpResponseas a string? - How do I get the response body unmarshalled directly into a Java pojo?
- Is the GET request made in the below code asynchronous?
I have tried looking into the Akka documentation and other sites but cannot find the answers anywhere.
final Http http = Http.get(actorSystem);
CompletionStage<HttpResponse> response =
http.singleRequest(HttpRequest.GET("http://127.0.0.1:8081/orders/24"));
HttpResponse httpResponse = response.toCompletableFuture().get();
Order s =
Jackson.unmarshaller(Order.class)
.unmarshal(
httpResponse.entity(),
ExecutionContexts.global(),
ActorMaterializer.create(actorSystem)
).toCompletableFuture()
.get();
System.out.println("response body: " + s); `