@Produces

The @javax.ws.rs.Produces annotation is used for defining the internet media type(s) that a REST resource class method can return to the client. You can define this either at the class level (which will get defaulted for all methods) or at the method level. The method-level annotations override the class-level annotations. The possible internet media types that a REST API can produce are as follows:

  • application/atom+xml
  • application/json
  • application/octet-stream
  • application/svg+xml
  • application/xhtml+xml
  • application/xml
  • text/html
  • text/plain
  • text/xml

The following example uses the @Produces annotation at the class level in order to set the default response media type as JSON for all the resource methods in this class. At runtime, the binding provider will convert the Java representation of the return value to the JSON format. This is discussed in the Understanding the data binding rules in JAX-RS section, which comes later in this chapter:

import javax.ws.rs.Path; 
import javax.ws.rs.Produces; 
import javax.ws.rs.core.MediaType; 
 
@Path("departments") 
@Produces(MediaType.APPLICATION_JSON) 
public class DepartmentService{ 
  //Class implementation goes here...     
} 
..................Content has been hidden....................

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