users@jersey.java.net

Re: [Jersey] Deployment: provider recognized, but not instantiated?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 23 Apr 2010 15:38:54 +0200

On Apr 23, 2010, at 2:28 PM, Marc Hadley wrote:

> On Apr 22, 2010, at 4:06 PM, Paul Sandoz wrote:
>>
>> I think there might is a bug in the MBW sorting algorithm.
>>
>> https://jsr311.dev.java.net/nonav/releases/1.1/spec/
>> spec3.html#x3-440004.2.2
>>
>> 4. 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.
>>
>> and i am doing this the opposite for the secondary key, doh! So
>> MessageBodyWriter<String> is sorted before
>> MessageBodyWriter<Object>, rather than the other way around.
>>
> I think the current behavior is correct. "object class" is a poor
> choice of phrase, it should be "entity object's class" or "the class
> of the entity object" instead. The intent is that writers whose
> generic type is closer to the actual type of the object being
> written are sorted ahead of those further away. This sorting allows
> more specific writers to override more generic ones.
>

Yes, i recall the discussions in the EG now (related to
StreamingOutput) and that is how i attempted to implement it in
Jersey, including appropriate tests.

However, i pre-sort the list of MBW/Rs, associated with a media type,
based on the distance of generic type to Object. This was an
optimization such that one did not have to do work at runtime. But i
am not sure it is correct in all circumstances, need to double check
as i could be trying to be too smart here! Plus when this sorting is
performed it does not ensure in all cases that application-based
registered MBW/Rs occur before system ones, and that is a bug.

Paul.