users@jersey.java.net

Re: [Jersey] JSON + XML : how to choose the return type ?

From: Casper Bang <casper_at_jbr.dk>
Date: Wed, 1 Apr 2009 20:31:12 +0200

Interesting new info. In trying to rewrite my custom header based Locale
detection method I arrive at the following:

        List<Variant> supportedVariants =
VariantListBuilder.newInstance().languages(
                        (Locale[]) getMySupportedLocales().toArray()
                ).build();

        request.selectVariant(supportedVariants).getLanguage()

...but that just results in weird error:

javax.servlet.ServletException: non-HTTP request or response
        com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:241)

So I agree with Felipe, a snipped would be handy. :)

/Casper


2009/4/1 Felipe Gaścho <fgaucho_at_gmail.com>

> do you have a code snippet ?
>
> On Wed, Apr 1, 2009 at 8:02 PM, Marc Hadley <Marc.Hadley_at_sun.com> wrote:
> > On Apr 1, 2009, at 12:07 PM, Felipe Gaścho wrote:
> >
> >> @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
> >>
> >> I know the return type depends of some parameter in the request .. but
> >> which one ? how to choose between JSON and XML in runtime ?
> >>
> >> may I choose this through a browser url ? or I need to create a http
> >> request in other way ?
> >>
> > You can use Request.selectVariant at runtime to have the JAX-RS impl
> select
> > the best matching representation from a set of available ones.
> >
> >
> https://jsr311.dev.java.net/nonav/releases/1.0/javax/ws/rs/core/Request.html#selectVariant(java.util.List)<https://jsr311.dev.java.net/nonav/releases/1.0/javax/ws/rs/core/Request.html#selectVariant%28java.util.List%29>
> >
> > Marc.
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> > For additional commands, e-mail: users-help_at_jersey.dev.java.net
> >
> >
>
>
>
> --
>
> Please help to test this application:
> http://fgaucho.dyndns.org:8080/cejug-classifieds-richfaces
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>