users@jersey.java.net

Re: [Jersey] need code samples for hooking in converters

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 16 Jun 2008 10:04:31 +0200

Jakub Podlesak wrote:
> Hi Victor,
>
> You can try to download Jersey bundle [1] and look at the [EntityProvider]
> example. You can also see some examples in blog entries [2] and [3].
> Some documentation could be found at [4].
>

The latest build now supports determining the content type of the
response in the absence of a @ProduceMime on a resource class. Although,
my preference would be to declare @ProduceMime on your resource classes
as it makes things less ambiguous, especially for other developers that
may look at the code.

The @ProduceMime on message body writers (previously called entity
providers but now split into readers and writers) is used to determine
the content type (based on what is acceptable). So if you do this:

   @Path("/")
   public class Resource {
     @GET
     public String get() { return "This is text/plain content"; }
   }

Then the content type returned (if acceptable) will be text plain, this
is because the String provider looks like this:

   @ProduceMime({"text/plain", "*/*"})
   @ConsumeMime({"text/plain", "*/*"})
   public final class StringProvider
       extends AbstractMessageReaderWriterProvider<String> {

Paul.

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109