I suspect you'll have to add a @XmlRootElement to GMDevice and EMDevice otherwise the JAXB MessageBodyWriter won't think it can marshall it since that annotation isn't inherited by subclasses.
Marc.
On Apr 9, 2010, at 5:34 AM, schong wrote:
> I am having problems using the Jersey/JAXB.
>
> I am trying to send back an abstract class called a MDevice which has two
> subclasses and GMDevice and EMDevice.
>
>
> @Path("/meterreadinstructions")
> public class MeterReadService {
>
>
>
> @GET
> @Produces("application/xml")
> @Path("{accountid}")
> public MDevice read(@PathParam("accountid") String accountId) {
>
> MDevice device = null;
>
> try{
> Meter meter = new MeterImpl();
> device =
> meter.findActiveMeterReadInstructionsForAccount(accountId);
> } catch (Exception e) {
> e.printStackTrace();
> throw new
> WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
> }
> if(device == null) {
> throw new WebApplicationException(Response.Status.NOT_FOUND);
> }
> return device;
> }
> }
>
> Even though I declared my object as a MDevice and return it through all the
> layers of my application as a MDevice, when I try to return it via my
> service, I get the following:
>
>
>
> Apr 9, 2010 9:17:42 AM com.sun.jersey.spi.container.ContainerResponse write
> SEVERE: A message body writer for Java type, class
> org.firstutility.services.entity.GMDevice, and MIME media type,
> application/xml, was not found
> Apr 9, 2010 9:17:42 AM
> com.sun.jersey.server.impl.application.WebApplicationImpl onException
> SEVERE: Internal server error
> javax.ws.rs.WebApplicationException
> at
> com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:241)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:689)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:612)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:603)
> at
> com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:309)
> at
> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:425)
> at
> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:590)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
> at
> com.sun.grizzly.http.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:188)
> at
> com.sun.grizzly.http.servlet.FilterChainImpl.invokeFilterChain(FilterChainImpl.java:137)
> at
> com.sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:278)
> at
> com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:165)
> at
> com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:726)
> at
> com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:615)
> at
> com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:895)
> at
> com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:162)
> at
> com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:136)
> at
> com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:103)
> at
> com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:89)
> at
> com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
> at
> com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:67)
> at
> com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
> at
> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
> at java.util.concurrent.FutureTask.run(FutureTask.java:138)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
> at java.lang.Thread.run(Thread.java:619)
>
> It looks like Jersey is dealing with the instance (GMDevice). Is this normal
> behaviour? Is there any way I could get it to use the abstract class?
>
> Thanks,
> Steve
> --
> View this message in context: http://n2.nabble.com/Returning-an-abstract-class-through-a-Jersey-restful-service-tp4876155p4876155.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>