Updated User to JSON request

The following solution updates the email address of the user we fetched in the preceding subsection:

user.getData().setEmail("[email protected]");

HttpRequest requestPut = HttpRequest.newBuilder()
.header("Content-Type", "application/json")
.uri(URI.create("https://reqres.in/api/users"))
.PUT(HttpRequest.BodyPublishers.ofString(jsonb.toJson(user)))
.build();

HttpResponse<User> responsePut = client.send(
requestPut, JsonBodyHandler.jsonBodyHandler(jsonb, User.class));

User updatedUser = responsePut.body();
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.91.254