Marshalling JSON to JAXB annotated POJO causes "UnmarshalException: unexpected element (uri:"", local:"xxxxx")" in RESTEasy client on EAP

Solution Unverified - Updated -

Issue

  • We are experiencing a content marshalling issue with EAP 6 when marshalling JSON to JAXB annotated POJO.
  • According to the RESTEasy documentation, "RESTEasy allows you to marshall JAXB annotated POJOs to and from JSON. This provider wraps the Jettison JSON library to accomplish this."
  • But in my case, it is not working and I am receiving the following error:
org.jboss.resteasy.plugins.providers.jaxb.JAXBUnmarshalException: javax.xml.bind.UnmarshalException
 - with linked exception:
[javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"should_be_ignored"). Expected elements are <{}message>,<{}return>]
  • Below is the actual class (note that we annotated @NoJackson to enable Jettison provider over Jackson explicitly):
@XmlRootElement(name="return")
@NoJackson
public class MyResponse {
    private List<Post> posts;

    @XmlElementWrapper(name = "messages")
    @XmlElement(name = "message")
    public List<Post> getPosts() { return posts; }

    public void setPosts(List<Post> posts) { this.posts = posts; }
}
  • And the JSON string I am receiving after posting a message:
{
    "should_be_ignored": {},
    "messages": [
        { ... }
    ],
    ...
}
  • Here is the RESTEasy client code running on EAP:
import org.jboss.resteasy.client.ClientRequest;
import org.jboss.resteasy.client.ClientResponse;

ClientRequest clientRequest = new ClientRequest("https://...");
ClientResponse<MyResponse> response = clientRequest.get(MyResponse.class);
MyResponse myResponse = response.getEntity();

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 5.x
    • 6.x
  • RESTEasy + Jettison provider

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