resteasy with jaxb and json
asotobu Jun 27, 2014 3:26 AMHi, I am developing an application which I want to be "100% fully compliant" across different Java EE vendors. Now it is a simple RESTful web application. The application works perfectly in Apache TomEE and Glassfish but not in Wildfly 8.1.0. Concretely it fails when try to unmarshal a rest call. Let me show an example (I have created one to make easy to follow).
I have next POJO:
@XmlRootElement public class BookInfo { private String title; private String author; public void setAuthor(String author) { this.author = author; } public String getAuthor() { return author; } public void setTitle(String title) { this.title = title; } public String getTitle() { return title; } }
And the service looks like:
@Singleton @Path("bookinfo") public class BookInfoService { @GET @Path("{isbn}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public BookInfo findBookByISBN(@PathParam("isbn") String isbn) { BookInfo bookInfo = new BookInfo(); bookInfo.setAuthor("XX"); bookInfo.setTitle("YY"); return bookInfo; } }
And I am using Arquillian and the test method is:
Client client = ClientBuilder.newClient(); BookInfo bookInfo = client.target(URI.create(new URL(base, "rest/").toExternalForm())).path("bookinfo/1111").request().get(BookInfo.class);
I am using Arquillian 1.1.5, Wildfly 8.1.0 and Jettison 3.0.8.
And the exception that is thrown in line 2 of test is:
javax.ws.rs.client.ResponseProcessingException: javax.ws.rs.ProcessingException: org.jboss.resteasy.plugins.providers.jaxb.JAXBUnmarshalException: javax.xml.bind.UnmarshalException - with linked exception: [com.sun.istack.SAXParseException2; columnNumber: 0; unexpected element (uri:"", local:"title"). Expected elements are <{}bookInfo>] at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:140) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:444) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.get(ClientInvocationBuilder.java:165)
I am not pretty sure why it works in all servers but not in Wildfly. I have googled a bit but I have not found any solution to this problem
If in test I do a get(String.class) I receive a correct json document so it seems that server side works perfectly.
Thank you so much for your time,
Alex.