April 2018
Intermediate to advanced
382 pages
10h 11m
English
As you can see, JAX-RS eases a lot of the objects parsing and represention:
@GET @Path("getUserFromBean") @Produces(MediaType.APPLICATION_JSON) public Response getUserFromBean(){ userFromBean = userBean.getUser(); return Response.ok(userFromBean).build(); } @GET @Path("getUserFromLocal") @Produces(MediaType.APPLICATION_JSON) public Response getUserFromLocal(){ return Response.ok(userLocal).build(); }
By using a Response returning object and @Produces(MediaType.APPLICATION_JSON), you give the framework the hard job of parsing your user object to a JSON representation. Lots of effort saved in a few lines!
You could also inject the user using a producer (the @Produces annotation). Check the CDI recipe from Chapter 1, New Features ...
Read now
Unlock full access