17.8. Interfaces, Abstract Classes, and JAXB

Some object models use abstract classes and interfaces heavily. JAXB does not work with interfaces that are root elements, and RESTEasy cannot unmarshal parameters that are interfaces or raw abstract classes because it lacks the information required to create a JAXBContext. For example:
 public interface IFoo {}

 @XmlRootElement
 public class RealFoo implements IFoo {}

 @Path("/jaxb")
 public class MyResource {

@PUT
@Consumes("application/xml")
public void put(IFoo foo) {...}
 }
In this example, RESTEasy would display an error ("Cannot find MessageBodyReader for..." or similar) because RESTEasy does not know that implementations of IFoo are JAXB classes, so it cannot create a JAXBContext for IFoo. As a workaround, you can annotate the interface with @XmlSeeAlso to correct the issue.

Note

This will not work with manual, hand-coded JAXB.
 @XmlSeeAlso(RealFoo.class)
 public interface IFoo {}
The extra @XmlSeeAlso on IFoo allows RESTEasy to create a JAXBContext that knows how to unmarshal RealFoo instances.