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

[jsr339-experts] Re: [jax-rs-spec users] MessageBodyWriter Class parameter

From: Sergey Beryozkin <sberyozkin_at_talend.com>
Date: Wed, 10 Oct 2012 12:56:32 +0100

By the way, injecting ResourceInfo can not be relied upon because MBW
does not really know if the type returned by Method is still the one, as
filters may have interfered.
So a bit of hack is needed to get

Book book - client.getBook(Book.class);

working with the code below...

Cheers, Sergey

On 09/10/12 16:51, Sergey Beryozkin wrote:
> On 09/10/12 15:40, Santiago Pericas-Geertsen wrote:
>> Sergey,
>>
>>> @GET
>>> public Book getBook() {
>>> if (something) {
>>> return SuperBook();
>>> } else {
>>> return SuperBook2();
>>> }
>>> }
>>
>> I'm assuming you mean "sub" not "super" here.
>>
> Yes, though I have a sub class called 'SuperBook' in my tests, meaning
> it has some super-book properties :-)
>
>>> I reckon in writeTo() it can make sense to get the return class
>>> reported by a given method to pass directly to writeTo, so that the
>>> provider can see that the first class parameter is 'Book.class',
>>> while the instance class is object.getClass().
>>
>> Without discussing the technical issue any further, this is not a
>> backward compatible change, right? What about injecting ResourceInfo
>> in 2.0 and getting the type from there?
>>
> I'm afraid it is not compatible indeed.
>
> Injecting ResourceInfo works.
>
> Cheers, Sergey
>
>> -- Santiago
>>
>>