Take the 2-minute tour ×

I'm using Jersey 1.1 (old, I know - have to because I'm stuck with Java 1.5). I'm doing a simple GET where a Java object is returned as the entity. The Java object is being marshalled correctly (Java to XML) because I can make the GET request via the web and it works great. I'm trying to use the Jersey client to make the GET request and unmarshall it back to the Java object and this is where it's failing. Shouldn't Jersey know how to unmarshall the XML it receives from the GET request back into the POJO since it's annotated correctly? It works on the server side. Here's the exception I get:

ClientHandlerException: A message body reader for Java type, class my.class.SearchResult, and MIME media type, application/xml was not found.

Here's the client code:

private SearchResult search() {
    WebResource wr = new Client().resource( "http://localhost:8080/MyProject/search" );
    return wr.get( SearchResult.class );

Here's the JAXB annotated POJO I'm using on the client and server:

@XmlRootElement(name = "searchResults")
@XmlType(name = "searchResults", propOrder = {
public class SearchResult {
    @XmlElement(name = "result")
    private List<Result> results = new ArrayList<Result>();

    public List<Result> getResults() {
        return results;

Here's the inner Result POJO as well:

@XmlType(name = "resultType", propOrder = {
public class Result {
    private String name;
    private String version;
    private String type;

Here's the GET service itself:

public class SearchRest {
    public SearchResult search() {
        SearchResult result = new SearchResult();
        return result;

Thank you!

share|improve this question
could you provide your Result class? –  Alex Stybaev May 17 '12 at 7:18
I edited the post with the Result class –  billsfan80 May 17 '12 at 14:06
May have found the solution on my own. I think putting jaxb jars in my classpath solved it. I was not getting any error to indicate they weren't there, but my guess is the @XmlRootElement annotation was being ignored at runtime because I had no jaxb jars in my classpath. Thoughts on this? –  billsfan80 May 17 '12 at 14:58

2 Answers 2

add the @XmlRootElement annotation to your Result class.

share|improve this answer
See my comment above, I think I solved it already. But as for your suggestion, why would I indicate the Result is the root element. How can I have two root elements? The SearchResult class is already annotated as the root. It contains a list of Result objects. –  billsfan80 May 17 '12 at 16:36
up vote 3 down vote accepted

I fixed the issue by adding the JAXB jars to my classpath on the client side. I don't know why this solved the problem but I would guess it's because the @XmlRootElement and other JAXB annotations in my POJOs were simply ignored at runtime because the jars were not present. This resulted in Jersey not detecting the annotations and thus thinking it had no way of translating between the xml and POJO on the client side. I discovered the solution when I tried the alternative way that avoids the need for annotations, where you wrap the root POJO in a JAXBElement. I updated the web service class to produce a JAXBElement and updated the client to expect the same. Then I got a NoClassDefFoundError that was more indicative of the missing jars, since I was referencing JAXBElement directly. I guess I got lucky.

share|improve this answer

Your Answer


