dev@jsr311.java.net

Re: JSR311: TypeLiteral

From: Bill Burke <bburke_at_redhat.com>
Date: Tue, 03 Jun 2008 14:57:40 -0400

Wow, that works? i'll have to check it out.

Marc Hadley wrote:
> Type erasure creates an issue for resource method return values. E.g.
> given:
>
> @GET
> 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:
>
> @GET
> 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
> information.
>
> 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:
>
> @GET
> Response getList() {
> List<Bean> results = ...;
> TypeLiteral<List<Bean>> listOfBean = new TypeLiteral<List<Bean>>() {};
> return
> Response.ok().entity(results).genericType(listOfBean).cacheControl(...).build();
>
> }
> Thoughts, comments ?
>
> Marc.
>
> [1]
> http://google-guice.googlecode.com/svn/trunk/src/com/google/inject/TypeLiteral.java
>
>
> ---
> Marc Hadley <marc.hadley at sun.com>
> CTO Office, Sun Microsystems.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jsr311.dev.java.net
> For additional commands, e-mail: dev-help_at_jsr311.dev.java.net
>

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