users@jersey.java.net

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

From: Victor Grazi <vgrazi_at_gmail.com>
Date: Mon, 16 Jun 2008 08:33:53 -0400

I wouldn't say I was against it, I was just thinking it would be more
reusable if the method that returned the java object would
automatically be delegated to the correct provider.

So for example, you don't annotate public MyClass myMethod() but you
do create providers for each of the supported types (and annotate
those)

On 6/15/08, Lars Tackmann <lars_at_randompage.org> wrote:
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>