-
Feature Request
-
Resolution: Done
-
Major
-
None
-
None
-
None
Ok, I looked into this a bit more...
Ken Brown wrote:
> > Hello,
> >
> > I am trying to get the following object model to work with 1.0 GA:
> >
> > @XmlSeeAlso(
)
> > interface IFoo
> >
> > @XmlSeeAlso(
)
> > @XmlTransient
> > abstract class BaseFoo implements IFoo
> >
> > @XmlRootElement
> > class RealFoo extends BaseFoo {...}
> > @XmlRootElement
> > class ImaginaryFoo extends BaseFoo
> >
> > and my resource:
> >
> >
> > @POST
> >
> > @Path("/bake")
> >
> > @Produces("application/json")
> >
> > @Consumes("application/json")
> >
> > public IFoo bake(IFoo foo) {...}
; // bake calls setXXXs on foo
> >
> >
> >
> > 1. JAXB. I tried many different combinations of XmlSeeAlso and other
> > approaches along the lines of
> > https://jaxb.dev.java.net/guide/Mapping_interfaces.html but all to no
> > avail. As soon as I involve the interface, I get 'no message body reader
> > found for type: interface IFoo'. What's the right incantation?
> >
Unless there's some magic, JAXB doesn't like interfaces very much. For
instance, if I do hand-coded JAXB as follows, JAXB throws an exception:
JAXBContext ctx = JAXBContext.newInstance(IFoo.class);
StringWriter os = new StringWriter();
ctx.createMarshaller().marshal(new RealFoo(), os);
If you change IFoo to to BaseFoo, this hand-coded JAXB will work:
JAXBContext ctx = JAXBContext.newInstance(BaseFoo.class);
StringWriter os = new StringWriter();
ctx.createMarshaller().marshal(new RealFoo(), os);
STILL this won't work with RESTEasy's JAXB providers because our
providers match based on @XmlRootElement or @XmlType. So, if you change
BaseFoo to have @XmlRootElement and use that as the parameter it will work:
@Path("/intf")
public static class MyResource
{
@POST
@Path("/bake")
@Produces("application/json")
@Consumes("application/json")
public IFoo bake(BaseFoo foo)
}
I guess I could search for @XmlSeeAlso as well, I'll add this.