Jersey Client Message Reader for Java Type Not Found

I am using Jersey 1.1 (the old one I know - should, because I am stuck with Java 1.5). I am doing a simple GET where a Java object is returned as an object. The Java object is properly ordered (Java-XML) because I can make a GET request over the Internet and it works great. I am trying to use a Jersey client to make a GET request and cancel it back to a Java object, and it is not. Should Jersey know how to reverse the XML token that it receives from a GET request back to POJO since it is properly annotated? 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 JAXB annotates the POJO that I use on the client and server:

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

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

Here is also the internal result of POJO:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "resultType", propOrder = {
    "name",
    "version",
    "type"
})
public class Result {
    private String name;
    private String version;
    private String type;
    ...
}

Here is the GET service itself:

@Path("/search")
public class SearchRest {
    @GET
    @Produces(MediaType.APPLICATION_XML)
    public SearchResult search() {
        SearchResult result = new SearchResult();
        ....
        return result;
    }
}

Thank!

+3
2

, JAXB- . , , , @XmlRootElement JAXB POJO , . , , , , xml POJO . , , , POJO JAXBElement. - JAXBElement , . NoClassDefFoundError, , JAXBElement. , .

+3

@XmlRootElement Result.

+3

All Articles