users@jersey.java.net

Re: [Jersey] Choosing a Provider for a MediaType in Ambiguous Conditions

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Tue, 7 Apr 2009 23:13:49 -0700

On Tue, Apr 7, 2009 at 6:05 AM, Marc Hadley <Marc.Hadley_at_sun.com> wrote:
> On Apr 7, 2009, at 4:22 AM, Paul Sandoz wrote:
>>
>> This is a known issue in JAX-RS.
>>
>> I think there is a way to fix this in Jersey by sorting the message body
>> readers/writers such that readers/writers with the most specific generic
>> type occur first and thus the isWriteable/isReadable if the more specifc
>> generic types are called first. (Such general sorting is non-trivial for
>> complex types, and there may be more than one solution, but for Class types
>> it is easy).
>>
> Note that sorting of providers based on closeness of generic type is
> required by JAX-RS 1.1, see step 4 of section 4.2.2 in the 1.1 draft spec
> (https://jsr311.dev.java.net/drafts/spec20090313.pdf). This corresponds to
> change C004 in the chnagelog
> (https://jsr311.dev.java.net/drafts/changelog.1.1.html).

Thanks! I hope something along the lines of what Paul was suggesting
could be made to work. I understand that automated ranking is a
non-trivial problem, even with Class - parametrized body
readers/writers.

But even if it was something as simple as de-prioritizing anything
that declares itself to handle Object.class would help in this
particular case.

-+ Tatu +-