There's more...

As you can see, JAX-RS eases a lot of object parsing and representation:

    @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 is saved in a few lines!

You could also inject the user using a producer (the @Produces annotation). Check the Jakarta CDI recipe from Chapter 1, New Features and Improvements, for more details.

..................Content has been hidden....................

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