[ 
https://issues.apache.org/jira/browse/CXF-5976?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14117819#comment-14117819
 ] 

Bin Zhu commented on CXF-5976:
------------------------------

Thanks Sergey for the update. Is there a patch for this fix? Or how could I 
find the binaries which included this fix? Download the latest source code and 
build it locally?

> incompatible with javax.xml.bind.JAXBElement error when using 
> List<JAXBElement<Book>>  as resource method param
> ---------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-5976
>                 URL: https://issues.apache.org/jira/browse/CXF-5976
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS, JAXB Databinding
>    Affects Versions: 3.0.1
>            Reporter: Bin Zhu
>            Assignee: Sergey Beryozkin
>             Fix For: 3.0.2, 3.1.0
>
>
> 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);
>     }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to