Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-189

Have JAXB providers handle class with only @XmlSeeAlso

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Done
    • Icon: Major Major
    • 1.0.1.GA
    • 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(

      {BaseFoo.class}

      )
      > > interface IFoo

      { ...}

      > >
      > > @XmlSeeAlso(

      {RealFoo.class,ImaginaryFoo.class}

      )
      > > @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)

      { return foo; }

      }

      I guess I could search for @XmlSeeAlso as well, I'll add this.

            patriot1burke@gmail.com Bill Burke (Inactive)
            patriot1burke@gmail.com Bill Burke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: