users@jersey.java.net

[Jersey] message body writer not found for a subclass of a JAXB annotated POJO

From: Pedro Pedruzzi <pedro.pedruzzi_at_gmail.com>
Date: Wed, 17 Aug 2011 09:30:31 -0300

Hello,

I've been playing with Jersey with JPA and came across an issue which
is blocking me from moving on with my tests. Basically I want to
return a serialized POJO to the client (xml or json) just fetched from
JPA.

My POJO is marked with JAXB annotations (@XmlRootElement for instance)
and it is working perfectly with Jersey when returning the actual
class.

However, JPA uses subclassing internally so I have no control over it.
The problem is that Jersey can't find the message body writer for the
subclass created by JPA and throws a message like this:

SEVERE: A message body writer for Java type, class [..], and MIME
media type, application/json, was not found
com.sun.jersey.server.impl.application.WebApplicationImpl onException

Is there any configuration to force Jersey use the body writer for my
JAXB POJO even in the case of a subclass being returned?

Obs.: This error doesn't happen if instead I return a List<> of this
POJO fetched from JPA.

Thanks in advance.

Regards,
-- 
Pedro Pedruzzi