users@jsr311.java.net

Re: declared return-type ignored for selection of MessageBodyWriter?

From: Reto Bachmann-Gmür <reto_at_gmuer.ch>
Date: Mon, 29 Sep 2008 17:54:15 +0200

Marc Hadley wrote:
> On Sep 29, 2008, at 10:45 AM, Reto Bachmann-Gmür wrote:
>
>> Marc Hadley wrote:
>>> It sounds like you are doing the correct thing. The generic type is
>>> either the declared return type of the method
>> Ok, so the follow-up question: is this the declared return type of the
>> method in the root-resource class or of the method in the superclass
>> or interface from where the annotations are taken (for the case where
>> the method in the root-resource inherits the annotations but declares
>> a more concrete return type)?
>>
> Good question. I can see arguments for either, what do others think ?
I've a weak preference for taking the method with the annotations, this
prevents unwanted side-effects when developer that are unaware of jax-rs
implement new subclasses while its usually easy to reproduce the
annotions on the subclass if the implementer wants a different
MessageBodyWriter to be selected.
>
>>> or the type returned by a GenericEntity instance.
>>> Unless I'm misunderstanding, I think this is somewhat orthogonal to
>>> issue 46 since that will only come into play during step 4 of section
>>> 4.2.2 (sorting to find the most appropriate writer). Writers can
>>> reject generic types they don't support in step 3 and then won't be
>>> considered in step 4.
>> I think to select the best of the possible combination of
>> resource-method and MessageBodyWriter satisfying a request, we should
>> know which writer will be selected before actually invoking a method.
>>
> Hmm, not sure if I understand you. You need to call the isWritable
> method at least once for each distinct combination of type, generic
> type, annotations and supported media type to determine if the writer is
> able to serialize the entity.
If we call isWritable with the declared type (and not with the type of
the object actually returned) we can identify all possible method-writer
pairs that would generate an acceptable response. Based on information
of the relative quality of both the method and the writer we can
determine the best pair. On the other hand, if the writer is selected
basing on the actually returned object we have to select the method
without knowing which provider will be used and thus without considering
its quality.

Reto
>
> Marc.
>
>>> On Sep 29, 2008, at 10:04 AM, Reto Bachmann-Gmür wrote:
>>>> Hello
>>>>
>>>> Rereading section 4.2.2 I'm insecure if its correct to look at the
>>>> declared return type of a method (for those that are not Response or
>>>> GenericEntity) for selecting the MessageBodyWriter.
>>>>
>>>> Currently I'm passing the type of the object returned at runtime as
>>>> the "type" argument to Providers.getMessageBodyWriter and the
>>>> declared return type as genericType.
>>>>
>>>> Does "for other return types it is the returned object." (section
>>>> 4.2.2) means that only the class of the object returned at runtime
>>>> is to be considered?
>>>>
>>>> Issue 46 I think would be easier to solve looking at the declared
>>>> return-type only, but currently it would be most useful to consider
>>>> both.
>>>>
>>>> Cheers,
>>>> reto
>>>>
>>> ---
>>> Marc Hadley <marc.hadley at sun.com>
>>> CTO Office, Sun Microsystems.
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jsr311.dev.java.net
>>> For additional commands, e-mail: users-help_at_jsr311.dev.java.net
>>
>>
>
> ---
> Marc Hadley <marc.hadley at sun.com>
> CTO Office, Sun Microsystems.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jsr311.dev.java.net
> For additional commands, e-mail: users-help_at_jsr311.dev.java.net
>