cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bin Zhu (JIRA)" <>
Subject [jira] [Created] (CXF-5976) incompatible with javax.xml.bind.JAXBElement error when using List<JAXBElement<Book>> as resource method param
Date Thu, 28 Aug 2014 11:06:57 GMT
Bin Zhu created CXF-5976:

             Summary: incompatible with javax.xml.bind.JAXBElement error when using List<JAXBElement<Book>>
 as resource method param
                 Key: CXF-5976
             Project: CXF
          Issue Type: Bug
          Components: JAX-RS, JAXB Databinding
    Affects Versions: 3.0.1
            Reporter: Bin Zhu

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.
    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.setTitle("echo " + bookElement.getValue().getTitle());
            JAXBElement<Book> element = new JAXBElement<Book>(new QName("book"),
Book.class, retBook);
        return ret;

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

    private Author author;
    private String title;

    public Author getAuthor() {
        return author;

    public void setAuthor(Author 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 =
                                        .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
                                       Object[] paramArray) throws Exception {
        paramArray = insertExchange(m, paramArray, exchange);
        if (LOG.isLoggable(Level.FINER)) {
            LOG.log(Level.FINER, "INVOKING_METHOD", new Object[] {serviceObject, 
        return m.invoke(serviceObject, paramArray);

This message was sent by Atlassian JIRA

View raw message