0

I just made a jax-rs service and I'm trying to convert the String I get from the service to entities. While with jax-rs everything is done automatically on the server side I assume there is a possibility to do it on the client side as well but I'm not finding it.

public class MyClient {

    public static void main(String[] args) {
        ResteasyClient client = new ResteasyClientBuilder().build();
        ResteasyWebTarget target = client.target("http://localhost:8080/restapp/api/paints/1");
        Response response = target.request().get();
        Paint values = response.readEntity(Paint.class);
        response.close();
    }
}

this give an e:

Exception in thread "main" javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find a MessageBodyReader of content-type application/json and type class client.Paint

(It works with String).

Ced
  • 15,847
  • 14
  • 87
  • 146
  • Do you have a JSON provider? – Paul Samsotha Nov 30 '15 at 12:59
  • @peeskillet I just have the resteasy client dependency on the client app. However I didn't add such thing as a provider on the server side, so I'm a bit confused about your question. – Ced Nov 30 '15 at 13:02
  • If you're using Maven, pick your RESTeasy version [here](http://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jackson2-provider), and add the dependency. If you're not using Maven, see [this post](http://stackoverflow.com/a/26678738/2587435) – Paul Samsotha Nov 30 '15 at 13:05
  • What server are yo using? If you're using Wildfly, it already has the provider. – Paul Samsotha Nov 30 '15 at 13:07
  • @peeskillet that was it indeed thanks! By the way so I can kill two birds with one stone, do you know how I can transform the `readEntity(Paint.class)` to accept a list of Paint objects ? – Ced Nov 30 '15 at 13:24
  • `readEntity(new GenericType>(){})` – Paul Samsotha Nov 30 '15 at 13:25
  • @peeskillet Thanks, I'll accept the anwser. – Ced Nov 30 '15 at 13:26
  • @peeskillet just letting you and future readers know that I had to use another method for the list. http://stackoverflow.com/questions/6349421/how-to-use-jackson-to-deserialise-an-array-of-objects – Ced Nov 30 '15 at 13:59

2 Answers2

1

You need to add a JSON provider. For RESTeasy, you can see this link and select your version, and add the dependency.

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jackson2-provider</artifactId>
    <version>${resteasy3.version}</version>
</dependency>
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
1

hi you can write ReastEasy or Jersy Client to get Json from your Service. how to write client you can follow :http://entityclass.in/rest/jerseyClientGetXml.htm