users@jersey.java.net

Re: [Jersey] Mixing templates with JAXB

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 09 Mar 2009 15:58:59 +0100

On Mar 5, 2009, at 7:29 PM, Alex Vollmer wrote:

> Is there a way to mix the default JAXB XML output with the Viewable
> templating stuff based on content negotiation? What I want is to
> define a resource method that returns a JAXB-annotated model object.
> If the the request is for XML, return XML. If it's for html then
> defer to the JSP template.
>

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.

> Any help would be appreciated.
>
> --Alex
>
> --
> Musings and notes -- http://alexvollmer.com