users@jersey.java.net

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

From: Mark Volkmann <mark_at_ociweb.com>
Date: Mon, 16 Jun 2008 08:37:31 -0500

On Jun 16, 2008, at 3:04 AM, Paul Sandoz wrote:

> 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> {


Where can I read about configuring message body readers and writers?
I'm guessing that I need to configure a mapping between Java classes
and their corresponding readers and writers somewhere. For example, if
I'm working with a Java class called Car that has fields like make,
model and year, do I need to configure the reader and writer that
handles creating a Car object from XML and creating XML from a Car
object?

---
Mark Volkmann