From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Tue, 03 Jun 2008 13:40:39 -0400

Type erasure creates an issue for resource method return values. E.g.

List<Bean> getList() {
   List<Bean> results = ...;
   return results;

we can determine the generic return type and find a suitable message
body writer. However, if the method needs to add additional metadata
then it has to return an instance of Response like this:

Response getList() {
   List<Bean> results = ...;
   return Response.ok().entity(results).cacheControl(...).build();

The problem is that because of type erasure we lose the type of list
that forms the entity. To get round this we'd like to add new methods
to ResponseBuilder that include a parameter that provides the missing
information and add a corresponding method to Response to extract that

Google Guice includes a TypeLiteral[1] class that seems to offer
everything we need and Bob Lee (Google) has kindly agreed to donate it
for inclusion in this JSR. Usage would look something like this:

Response getList() {
   List<Bean> results = ...;
   TypeLiteral<List<Bean>> listOfBean = new TypeLiteral<List<Bean>>()
Thoughts, comments ?



Marc Hadley <marc.hadley at>
CTO Office, Sun Microsystems.