users@jersey.java.net

[Jersey] How to configure JSON POJO in Jersey 2.0 client?

From: agks mehx <agksmehx_at_gmail.com>
Date: Sun, 28 Apr 2013 17:22:54 -1000

The the following Exception is thrown by running the code that follows it.
What do I need to do to get JSON work properly in the client?

Exception in thread "main"
org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException:
MessageBodyReader not found for media type=application/json, type=class
com.younum.test.foo.User, genericType=class com.younum.test.foo.User.
at
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:173)

-----------------

package com.example.test.foo;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class User {

  public String id;
  public String name;

  public static void main (String [] args) {
    Client client = ClientBuilder.newClient();
    WebTarget web_target = client
        .target("https://graph.facebook.com/skra95");
    User me = web_target
        .request()
        .accept(MediaType.APPLICATION_JSON_TYPE)
        .buildGet()
        .property("access_token", "a_valid_access_token")
        .invoke(User.class);
    System.out.println(me);
  }

}