jsr339-experts@jax-rs-spec.java.net

[jsr339-experts] Re: finer-grain reader/writer matching

From: Roberto Chinnici <roberto.chinnici_at_oracle.com>
Date: Fri, 04 Mar 2011 10:41:09 -0800

  On 3/4/11 6:19 AM, Bill Burke wrote:
> In the message body reader/writer matching algorithm add an additional
> sort so that template variables take precedence. For example
>
>
> @Produces("application/xml")
> public class FooWriter implements MessageBodyWriter<Foo> {...}
>
> takes precedence over:
>
> @Produces("application/xml")
> public class JaxbWriter implements MessageBodyWriter {...}
>
>
> Users may want to override the default JAXB (or other) provider for a
> specific java type.

I filed JAX_RS_SPEC-47 [1].

Looking at the spec, the sorting step of the algorithm for readers
4.2.1.(4) doesn't mention generics, but the corresponding step for
writers 4.2.2.(4) does. The latter says:

[[
Sort the selected MessageBodyWriter providers with a primary key of
media type (see section 4.2.3) and a secondary key of generic type where
providers whose generic type is the nearest superclass of the object
class are sorted first.
]]

The language is a little imprecise, mixing types and subclassing, but I
think by "generic type" it means the actual type parameter of the
provider. So in your example FooWriter should appear before JaxbWriter
when writing a Foo instance.

I may have to look into the archives for JAX-RS 1.0 to find the
rationale for the different handling of readers and writers.

[1] http://java.net/jira/browse/JAX_RS_SPEC-47