On Feb 24, 2009, at 9:40 AM, Jordi Domingo Borràs wrote:
> Hi Paul,
>
> What do you think about overloading the method and passing the class
> type, something like
>
> public Response getPersones() {
> return
> Response.ok().entity(listPersones(),Persona.class).build();
>
> }
>
Unfortunately that is not a generic solution to the issue, what if i
had a type of Map<String, String> or List<Set<String>> ?
The only generic solution we found was to use another class,
GenericEntity, to keep hold of the type information. This solution was
inspired by Guice 1.0, which provides something similar.
The other solution instead of List<Persona> is to use Persona[], since
the array type is not erased by an instance of the array.
Paul.
> Thanks for your help!
>
> Jordi
>
> Hi Jordi,
>
> See the following:
>
> http://markmail.org/search/?q=list%3Anet.java.dev.jersey.users+GenericEntity+order%3Adate-backward#query
>
> :list%3Anet.java.dev.jersey.users%20GenericEntity%20order%3Adate-
> backward+page:1+mid:fp2o45igab4vg2zc+state:results
>
> The problem is one of type erasure. The generic type information of
> List<Persona> is lost as soon as an instance is created thus we need
>
> to retain the information using GenericEntity.
>
> An alternative to using a list is to use an array and such information
> is not lost.
>
> Hope that helps,
> Paul.
>
> [1] https://jsr311.dev.java.net/nonav/javadoc/javax/ws/rs/core/GenericEntity.html
>
>
> On Feb 23, 2009, at 12:41 PM, Jordi Domingo Borràs wrote:
>
> > Hi!
> >
> > Im getting this error:
> >
> > GRAVE: A message body writer for Java type, class
> > java.util.ArrayList, and MIME media type, application/xml, was not
>
> > found
> > 23-feb-2009 12:35:39
> > com.sun.jersey.server.impl.application.WebApplicationImpl
> onException
> > GRAVE: Internal server error
> > javax.ws.rs.WebApplicationException
> > at
>
> > com
> > .sun
> >
> .jersey.spi.container.ContainerResponse.write(ContainerResponse.java:
> > 240)
> > at
> > com
> > .sun
> > .jersey
> > .server
> > .impl
> > .application
>
> > .WebApplicationImpl._handleRequest(WebApplicationImpl.java:593)
> > at
> > com
> > .sun
> > .jersey
> > .server
> > .impl
> > .application
> > .WebApplicationImpl.handleRequest(WebApplicationImpl.java:514)
>
> > at
> > com
> > .sun
> > .jersey
> > .server
> > .impl
> > .application
> > .WebApplicationImpl.handleRequest(WebApplicationImpl.java:505)
> > at
> > com
>
> > .sun
> > .jersey
> > .spi
> > .container.servlet.ServletContainer.service(ServletContainer.java:
> 359)
> > at javax.servlet.http.HttpServlet.service(HttpServlet.java:
> > 717)
> > at
>
> > org
> > .apache
> > .catalina
> > .core
> >
> .ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
> > 290)
> > at
> > org
> > .apache
> > .catalina
>
> > .core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
> 206)
> > at
> > org
> > .apache
> >
> .catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
> > 233)
>
> > at
> > org
> > .apache
> >
> .catalina.core.StandardContextValve.invoke(StandardContextValve.java:
> > 191)
> > at
> > org
> > .apache
> > .catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
>
> > at
> > org
> > .apache
> > .catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
> > at
> > org
> > .apache
> > .catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
>
> > 109)
> > at
> > org
> > .apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
> > 286)
> > at
> > org
> > .apache.coyote.http11.Http11Processor.process(Http11Processor.java:
>
> > 845)
> > at org.apache.coyote.http11.Http11Protocol
> > $Http11ConnectionHandler.process(Http11Protocol.java:583)
> > at org.apache.tomcat.util.net.JIoEndpoint
> > $Worker.run(JIoEndpoint.java:447)
>
> > at java.lang.Thread.run(Thread.java:619)
> >
> > Trying to do :
> >
> >
> > @GET
> > @Produces({"application/json","application/xml"})
> > public Response getPersones() {
>
> > ResponseBuilder rb = Response.ok().entity(listPersones());
> > return rb.build();
> > }
> >
> > The method listPersones() just returns an List<Persona>
> >
> > If i return a List<Persona>, just the same without wrapping it into
>
> > a response, everything goes fine:
> >
> > @GET
> > @Produces({"application/json","application/xml"})
> > public List<Persona> getPersones() {
> > return listPersones();
>
> > }
> >
> > I dont know if its a bug or Im doing something wrong.. I need your
> > help :)
> >
> > Thanks!
> >
> > Jordi
> >