Java Reference
In-Depth Information
}
@POST
@Path("/{id}")
public Response bookPlace(@PathParam("id") int id) {
try {
theatreBooker.bookSeat(id);
return
Response.ok(SeatDto.fromSeat(theatreBox.getSeat(id)))
.build();
} catch (Exception e) {
final Entity<String> errorMessage = Entity
.json(e.getMessage());
return
Response.status(Response.Status.BAD_REQUEST)
.entity(errorMessage).build();
}
}
}
If you have understood our earlier section well, this code will be almost intuitive to you.
We have included two methods here, just like the SOAP alter ego; the former one is
named getSeatList , which is bound to an HTTP GET request and produces the list of
Seats . The list is returned using a JSON representation that is pretty common when re-
turning Java objects to the client.
Note
The grammar for JSON objects is simple and requires the grouping of the data definition
and data values; it is as follows:
• Elements are enclosed within curly brackets ( { and } )
• Values of elements come in pairs with the structure of name:value and are
comma separated
• Arrays are enclosed within square brackets ( [ and ] )
That's all there is to it (for the full JSON grammar description, visit http://www.json.org/ ) .
Search WWH ::




Custom Search