Example: content negotation
@Consumes is an array of media types that a particular resource or resource method consumes. For example: @Consumes("text/*") @Path("/library") public class Library { @POST public String stringBook(String book) {...} @Consumes("text/xml") @POST public String jaxbBook(Book book) {...} When a client makes a request, JAX-RS first finds all methods that match the path, then, it sorts things based on the content-type header sent by the client. So, if a client sent: POST /library content-type: text/plain thsi sis anice book The stringBook() method would be invoked because it matches to the default "text/*" media type. Now, if the client instead sends XML: POST /library content-type: text/xml The jaxbBook() method would be invoked. The @Produces is used to map a client request and match it up to the client's Accept header. The Accept HTTP header is sent by the client and defines the media types the client prefers to receive from the server. @Produces("text/*") @Path("/library") public class Library { @GET @Produces("application/json") public String getJSON() {...} @GET public String get() {...} So, if the client sends: GET /library Accept: application/json The getJSON() method would be invoked