users@jersey.java.net

[Jersey] Problem with JAXBContext

From: Ricardo Borillo <Ricardo.Borillo_at_si.uji.es>
Date: Wed, 12 Jan 2011 15:00:02 +0100

Hi all,

He have a common project that defines a JAXB class for message issue:

@XmlRootElement
public class ResponseMessage<T>
{
    private boolean success;
    private String msg;
    private List<T> data;

    ...
}

The problem arises when we try to build a Response based on this class
in a Jersey method:

   @Path("xxx")
   public Response method1() {
       List<ClassA> data = ...;
       return Response.ok(new ResponseMessage<ClassA>(true, "xxx",
data)).build();
   }

This causes an exception:

Caused by: javax.xml.bind.JAXBException: class ClassA nor any of its
super class is known to this context.
        at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:590)
        at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:648)

ResponseMessage is in package a.b.c, for example and ClassA in a.x.y.

We suppose that Jersey initialize a context that doesn't include
ClassA and we want to know if there's any workaround that not involves
the definition of a @Provider each time implementing
ContextResolver<JAXBContext> ... The problem is that we use this
construction in several project and define the provider each time is
not very straightforward.

---
Salut,
====================================
Ricardo Borillo Domenech
http://xml-utils.com
twitter: @borillo