Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-5976

incompatible with javax.xml.bind.JAXBElement error when using List<JAXBElement<Book>> as resource method param

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.1
    • 3.0.2, 3.1
    • JAX-RS, JAXB Databinding
    • None
    • Unknown

    Description

      I'm migrating App to CXF3.0.1 from wink. There will be ClassCastException if I using JAXBElement List (e.g. List<JAXBElement<Book>>) in the resource method.
      e.g.
      @Path("booklistjaxbelement")
      @Produces(MediaType.APPLICATION_XML)
      @Consumes(MediaType.APPLICATION_XML)
      @POST
      public List<JAXBElement<Book>> echoJAXBElementBookList(List<JAXBElement<Book>> bookElements) {
      List<JAXBElement<Book>> ret = new ArrayList<JAXBElement<Book>>();
      Author author = null;
      Author retAuthor = null;
      Book retBook = null;
      for (JAXBElement<Book> bookElement : bookElements)

      { author = bookElement.getValue().getAuthor(); retAuthor = new Author(); retAuthor.setFirstName("echo " + author.getFirstName()); retAuthor.setLastName("echo " + author.getLastName()); retBook = new Book(); retBook.setAuthor(retAuthor); retBook.setTitle("echo " + bookElement.getValue().getTitle()); JAXBElement<Book> element = new JAXBElement<Book>(new QName("book"), Book.class, retBook); ret.add(element); }

      return ret;
      }

      Book is an JAXB bean like this:
      @XmlRootElement
      public class Book {

      private Author author;
      private String title;

      public Author getAuthor()

      { return author; }

      public void setAuthor(Author author)

      { this.author = author; }

      public String getTitle()

      { return title; }

      ....
      Test client is like this:

      List<Book> source = getBookSource();
      Resource resource = client.resource(JAXB_BASE_URI + "/booklistjaxbelement");
      ClientResponse response =
      resource.accept(MediaType.APPLICATION_XML).contentType(MediaType.APPLICATION_XML)
      .post(new GenericEntity<List<Book>>(source) {
      });
      List<Book> responseEntity = response.getEntity(new EntityType<List<Book>>() {
      });
      -------------------
      Debugged CXF code and find in AbstractInvoker. performInvocation, it will invoke the method.invoke. The value of paramArray here is Book ArrayList and caused this issue.
      This scenario is working in wink, but doesn't work here...

      protected Object performInvocation(Exchange exchange, final Object serviceObject, Method m,
      Object[] paramArray) throws Exception {
      paramArray = insertExchange(m, paramArray, exchange);
      if (LOG.isLoggable(Level.FINER)) {
      LOG.log(Level.FINER, "INVOKING_METHOD", new Object[]

      {serviceObject, m, Arrays.asList(paramArray)}

      );
      }
      return m.invoke(serviceObject, paramArray);
      }

      Attachments

        Activity

          People

            sergey_beryozkin Sergey Beryozkin
            beanoct Bin Zhu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: