users@jersey.java.net

Re: [Jersey] Parameter "type" in MessageBodyWriter

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 16 Apr 2009 11:28:58 +0200

On Apr 15, 2009, at 10:08 PM, Jaka JanĨar wrote:

> Hi!
>
> It's me with my type questions again :)
>
> I was wondering, is the type parameter in MessageBodyWriter redundant,
> given that we have genericType?
>

Not quite, see below. Also it is a PITA to have to check the instance
of the genericType for the common case of where the genericType is an
instance of Class, and type == genericType.


> That is, is there a situation when type isn't equal to:
>
> genericType instanceof ParameterizedType
> ? ((ParameterizedType) genericType).getRawType()
> : genericType;
>

The type will be the same or a sub class of the raw type. Or put
another way:

(ParameterizedType) genericType).getRawType().isAssignableFrom(type);


Paul.