dev@jsr311.java.net

Type erasure and MessageBodyWriter matching

From: Bill Burke <bburke_at_redhat.com>
Date: Thu, 27 Mar 2008 12:50:53 -0400

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?


-- 
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com