Re: JSR311: Type erasure and MessageBodyWriter matching

From: Stephan Koops <>
Date: Thu, 27 Mar 2008 18:06:44 +0100

Hi Bill,

maybe useful.

(before start:) IMO it should be a method of the ResponseBuilder and a
getter in Request.

what do you want to give the method in this case?
String>.class) does not work.
responseBuilder.setEntityGenericType(String.class) is not useful for the
MultivaluedMap, because it needs two arguments. For a MultivaluedMap we
need to call responseBuilder.setEntityGenericType(String.class,
I think ResponseBuilder.setEntityGenericType(Class...) [instead of
Type...] is enough. Do I miss something?


Bill Burke schrieb:
> Because of type erasure in Java, you cannot get the types of a
> parameterized generic from an object instance.
> I ran into this recently when trying to write a MessageBodyWriter for
> application/x-www-form-urlencoded + MultivaluedMap<String, String>.
> My provider was doing generic type evaluation to determine if the
> returned object was and instance of Multivalued<String, String>.
> This works great if you match the resource's method's return type.
> You can get the generic type information.
> But for Response, it is impossible to get the generic type information
> as you cannot extract it from the Response.getEntity().getClass().
> I don't know if we need or want a
> Response.setEntityGenericType(Type type); method.
> Following me?