I have a JAX-RS client that makes a simple GET request. I am using the CXF and Spring implementation for DI. The call completed successfully and I get a 200 response code back. But I get an error while reading the response in my POJO.
An exception:
[2015-05-08 16:11:55,457][ERROR][org.apache.cxf.jaxrs.utils.JAXRSUtils]: No message body reader has been found for class com.voya.refapp.domain.Customer, ContentType: application/json [2015-05-08 16:11:55,468][ERROR][com.voya.refapp.service.CustomerServiceImpl]: filterByName() - Exception occurred javax.ws.rs.client.ResponseProcessingException: No message body reader has been found for class com.voya.refapp.domain.Customer, ContentType: application/json at org.apache.cxf.jaxrs.impl.ResponseImpl.reportMessageHandlerProblem(ResponseImpl.java:433) ~[cxf-rt-frontend-jaxrs-3.0.4.jar:3.0.4] at org.apache.cxf.jaxrs.impl.ResponseImpl.doReadEntity(ResponseImpl.java:384) ~[cxf-rt-frontend-jaxrs-3.0.4.jar:3.0.4]
The code:
Client client = ClientBuilder.newClient(); WebTarget target = client.target("http://localhost:8080/rest").path("customers/1"); Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON_TYPE); Response response = builder.get();
I have the dependency below suggested in this answer in my classpath, it doesn't seem to be matched automatically.
<dependency> <groupId>com.fasterxml.jackson.jaxrs</groupId> <artifactId>jackson-jaxrs-json-provider</artifactId> </dependency>
I also tried registering the json provider when creating the client:
Client client = ClientBuilder.newClient().register(new JacsksonJsonProvider());
and
Client client = ClientBuilder.newClient().register(JacsksonJsonProvider.class);
But none of these options worked. I got another exception when I registered the json provider using one of the options above:
javax.ws.rs.client.ResponseProcessingException: Problem with reading the data
Update:
Registering a json provider worked fine using ClientBuilder.newClient().register(JacsksonJsonProvider.class) . The problem was that the data (for example, the above exception is clearly stated). I feel stupid now :() I had a logical field in json called "active", but it was called "isActive" in POJO. @JsonProperty("active") annotation in a field in POJO, it started working fine
java rest jackson jax-rs cxf
Anand jayabalan
source share