How it works...

First, our remote endpoint is creating User and converting it to a response entity:

return Response.ok(new User(id, "User " + id)).build();

So, with no effort at all, your User is now a JSON object.

Now let's take a look at the key method in AsyncResultClient:

    public CompletionStage<Response> getResult(){        return target.request(MediaType.APPLICATION_JSON).rx().get();    }

The rx() method is a part of the Reactive Client API introduced in Java EE 8. We'll discuss reactive in more detail in the next chapter. It basically returns CompletionStageInvoker, which will allow you to get CompletionStage<Response> (the returning value for this method).

In other words, this is an asynchronous/non-blocking code that gets results from the ...

Get Java EE 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.