users@jersey.java.net

Re: [Jersey] Mixing templates with JAXB

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 10 Mar 2009 11:27:16 +0100

On Mar 9, 2009, at 9:21 PM, Alex Vollmer wrote:

> On Mar 9, 2009, at Mar 9, 7:58 AM, Paul Sandoz wrote:
>
>> You can do things explicitly:
>>
>> @Produces("application/xml")
>> public Bean getBean() {
>> ...
>> }
>>
>> @Produces("text/html")
>> public Viewable getViewable() {
>> return new Viewable("index", this);
>> }
>>
>>
>> If you want to above behavior implicitly, then if you are using
>> Jersey 1.0.2, you can do:
>>
>>
>> @ImplicitProduces("text/html")
>> public class MyResource {
>> @Produces("application/xml")
>> public Bean getBean() {
>> ...
>> }
>> }
>>
>> Paul.
>
> What would this look like if one were to tweak the bookstore
> example? Sorry, but I'm still a little unclear on exactly how to do
> this. Do I need a separate method for each content-type? If so, does
> each one repeat the same HTTP method and path annotations, but
> specifies a different @Produces annotation?
>

Yes, if you want to be explicit.


> I've added JAXB annotations to the Item type, but haven't been able
> to get different results based on different Accept headers (using
> the curl command-line tool for testing). Any help is appreciated.
>

If you want to be implicit, see the patch that James has included
(that i plan to apply as soon as GF embedded support works correctly
with JSPs):

   https://jersey.dev.java.net/issues/show_bug.cgi?id=190
   https://jersey.dev.java.net/nonav/issues/showattachment.cgi/21/working_tests_with_jetty.patch

Paul.