Roshni Prasad
Roshni Prasad
Branch Unspecified
29 Mar 2016

What is the use of @Produces("application/pdf") in real time ?

While going through the basics of rest web services I have seen the use of Download Files from (JAX-RS) RESTful Web Service.
Can some one please let me know the actual use of
@Produces(“text/plain“)
@Produces(“image/your image type[.jpg/.png/.gif]”)
@Produces(“application/pdf“)
Jason Estibeiro

Jason Estibeiro

Branch Unspecified
2 years ago
The @Produces annotation is used to specify the MIME media types of representations a resource can produce and send back to the client. Also, in the response sent back to the client the response header `Content-Type` is set to the MIME type passed to the annotation.

So,
@Produces(“text/plain“) 
will generate a response which will contain just plain text.

@Produces(“application/pdf“)
will generate a response with a document in .pdf format.

This documentation link has explained it very well. Do have a look at it.
Roshni Prasad

Roshni Prasad

Branch Unspecified
2 years ago
Jason Estibeiro
The @Produces annotation is used to specify the MIME media types of representations a resource can produce and send back to the client. Also, in the response sent back to the client the response header `Content-Type` is set to the MIME type passed to the annotation.

So,
@Produces(“text/plain“) 
will generate a response which will contain just plain text.

@Produces(“application/pdf“)
will generate a response with a document in .pdf format.

This documentation link has explained it very well. Do have a look at it.
Hi Jason,
Thanks for the reply.
I would like to tell you that I am aware of the basic usage of @Produces.
What I wanted to know is can we use @Produces(“application/pdf“) in-order to convert a java object to PDF file?

Share this content on your social channels -

Only logged in users can reply.