users@jersey.java.net

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

From: Lars Tackmann <lars_at_randompage.org>
Date: Sun, 15 Jun 2008 17:50:54 +0200

On Sun, Jun 15, 2008 at 8:04 AM, Victor Grazi <vgrazi_at_gmail.com> wrote:
> Using the JAX-RS API, I am assuming there is a way to automatically
> transform custom objects to any of a number of supported output formats.
> But it is not clear to me how it is done or what the life cycle would be.
>
> For example, I would like to be able to create a method that returns a Java
> object (of a specified type @GET public MyClass someGetMethod() - no
> @ProduceMime specified), and depending on the Content-Type in the HTTP
> request, have a custom converter automatically invoked that would serialize
> that Java object to any of the Content-Types supported by my application
> (xml, plain text, etc), and automatically return the converted result in the
> response.

Not sure if I am missing something here, but have you looked at
implementing your own provider classes ? (see "Message Body Providers"
here
http://cwiki.apache.org/CXF20DOC/jax-rs-jsr-311.html). I use these
today to perform some custom XML convertion, and it works great. Out
of curiosity
 why are you against the use of @ProduceMime ? - it helps you
correctly handle the case when people are sending requests for media
types you
cannot handle. (i.e. return 415).

-- 
Yours sincerely
Lars Tackmann