JAXB marshalling gets "UnmarshalException: unexpected element (uri:"", local:"xxxxx")" in RESTEasy client on EAP

Solution Unverified - Updated -

Issue

  • RESTEasy client is not able to convert the received JSON response into JSON object.
  • My Resource code:
    @GET
    @Path("/customer/{id}")
    public Response getCustomer(@PathParam("id") int id) {
        Customer customer = ...
        return Response.ok(customer).build();
    }
  • Customer Class:
@XmlRootElement(name = "customer")
@XmlType(propOrder = {"firstName", "lastName", ...})
public class Customer {
    private int id;
    private String firstName;
    private String lastName;
    ...
  • Client code:
    @Test
    public void getCustomer() throws Exception {
        ClientRequest request = new ClientRequest("http://localhost:8080/sample/customer/1");
        ClientResponse<Customer> response = request.get(Customer.class);
        Customer customer = response.getEntity();
        ...
  • The exception I am getting:
org.jboss.resteasy.plugins.providers.jaxb.JAXBUnmarshalException: javax.xml.bind.UnmarshalException
 - with linked exception:
[com.sun.istack.SAXParseException2; columnNumber: 0; unexpected element (uri:"", local:"id"). Expected elements are <{}customer>]
    at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.readFrom(AbstractJAXBProvider.java:119)
    at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:105)
    at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.read(GZIPDecodingInterceptor.java:63)
    at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:108)
    at org.jboss.resteasy.client.core.BaseClientResponse.readFrom(BaseClientResponse.java:433)
    at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:377)
    at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:338)
    at com.sample.app.test.RestEasyClientTest.getCustomer(RestEasyClientTest.java:86)
    ...

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content