users@jersey.java.net

[Jersey] json client example?

From: <agksmehx_at_gmail.com>
Date: Thu, 29 Mar 2012 19:21:48 +0000 (GMT)

i currently have an awkward if not inefficient way to use the client to
read json into java class.

could somebody please give me the best way to do this?

my current code is at:
http://stackoverflow.com/questions/9914015/how-to-consume-facebook-json
-using-jersey-client

quoted here:

package com.foo.json;

import javax.xml.bind.annotation.XmlRootElement;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;

@XmlRootElement
public class Me {

    public String id;
    public String name;

    public static void main(String[] args) {
        Client client = Client.create();
        WebResource web_resource =
client.resource("https://graph.facebook.com/me?fields=id,name&access_to
ken=deleted");
        Me response = web_resource.get(Me.class);
        System.out.println(response);
    }

}

This doesn't work and gives an exception. What makes it work is adding
the following:

        JSONJAXBContext json_jaxb_context = new
JSONJAXBContext(Me.class);
        String response = web_resource.get(String.class);
        Me me =
json_jaxb_context.createJSONUnmarshaller().unmarshalFromJSON(new
StringReader(response), Me.class);

I hope somebody can tell me how to wire it directly so that I can use
`web-resource.get(Me.class)`