users@jersey.java.net

Re: [Jersey] Implementing a generic javax.ws.rs.core.Response

From: Jaka Jančar <jaka_at_kubje.org>
Date: Tue, 31 Mar 2009 17:15:06 +0200

On 31. Mar 2009, at 17:06, Marc Hadley wrote:

> On Mar 31, 2009, at 10:47 AM, Paul Sandoz wrote:
>>
>>> All of this would be, I think, acheivable in an easy way (without
>>> requiring the returning of anonymous subclasses) if
>>> MessageBodyWriter had another parameter that would receive the
>>> return type of the resource method, e.g. "Type
>>> resourceMethodReturnType", similar to how "annotations" receives
>>> it's annotations:
>>>
>>> boolean isWriteable(
>>> java.lang.Class<?> type,
>>> java.lang.reflect.Type genericType,
>>> java.lang.annotation.Annotation[] annotations,
>>> java.lang.reflect.Type resourceMethodReturnType, /* NEW */
>>> MediaType mediaType)
>>>
>>> This would be analogous to genericType parameter in
>>> MessageBodyReader, which receives the type of the parameter. It
>>> would differ from genericType in MessageBodyWriter in that it
>>> would always get the return type of the method and never do
>>> runtime inspection, but instead let the provider infer the type on
>>> its own. Basically doing less than what is done now for genericType.
>>>
>>> If you look at table 3.1 of the spec, you'll see that columns 2, 3
>>> and 4 are available to MessageBodyWriter, but the first one really
>>> isn't, which is exactly what resourceMethodReturnType would provide.
>>>
>>> What do you think?
>>>
>>
> I'm confused, doesn't the genericType parameter give you exactly
> what you need if you define your own generic response type ?
>

Not if it extends Response, e.g.
   MyResponse<T> extends Response.

If it doesn't extend it, you can't specify a custom status code, afaik.