users@jersey.java.net

Re: [Jersey] Server prioritization of media types

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 18 Dec 2009 19:20:25 +0100

On Dec 18, 2009, at 4:04 PM, Paul Sandoz wrote:
>>> OK, are your fine with the proposed syntax?
>>
>> Yes, looks good to me!
>>
>> I guess its not possible to use a ">" token instead of "," when
>> passing multiple MIME types as a single String with @Produces? Was
>> just wondering if ordering could be combined into @Produces such as
>> @Produces("text/html > text/xml") etc. If its not easily possible
>> then
>> for sure the @ProducesOrder sounds good to me
>>
>
> I was wondering that too. Let me think about it.
>

One possible solution is as follows:

  public class X {
    @GET
    @Produces("(application/xml, text/xml) > (application/json)")
    public ... getXml() { ... }

    @GET
    @Produces("application/json")
    public ... getJson() { ... }

    @GET
    @Produces("(text/html, application/html) > (text/xml, application/
xml)")
    public Viewable getHtml() { ... }
  }

But i think that is over complicated.

Another solution is to define a relative priority integer value:

  public class X {
    @GET
    @Produces("application/xml;p=2, text/xml;p=2")
    public ... getXml() { ... }

    @GET
    @Produces("application/json") // p=1
    public ... getJson() { ... }

    @GET
    @Produces("text/html;p=3, application/html;p=3")
    public Viewable getHtml() { ... }
  }

  @ImplicitProduces("text/html;p=3, application/html;p=3")
  public class X {
    @GET
    @Produces("application/xml;p=2, text/xml;p=2")
    public ... getXml() { ... }

    @GET
    @Produces("application/json") // p=1
    public ... getJson() { ... }
  }

And is it easy to support a media list property for an application
wide setting.

In fact we could probably reuse "qs" in this respect. I doubt that it
will break backwards compatibility as the intent was to achieve the
same result.

Paul.