Мой код не работает:
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_token=deleted");
Me response = web_resource.get(Me.class);
System.out.println(response);
}
}
Ошибка:
Mar 28, 2012 11:56:43 AM com.sun.jersey.api.client.ClientResponse getEntity
SEVERE: A message body reader for Java class com.foo.json.Me, and Java type class com.foo.json.Me, and MIME media type text/javascript; charset=UTF-8 was not found
Mar 28, 2012 11:56:43 AM com.sun.jersey.api.client.ClientResponse getEntity
SEVERE: The registered message body readers compatible with the MIME media type are:
*/* ->
com.sun.jersey.core.impl.provider.entity.FormProvider
com.sun.jersey.core.impl.provider.entity.StringProvider
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
com.sun.jersey.core.impl.provider.entity.FileProvider
com.sun.jersey.core.impl.provider.entity.InputStreamProvider
com.sun.jersey.core.impl.provider.entity.DataSourceProvider
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
com.sun.jersey.core.impl.provider.entity.ReaderProvider
com.sun.jersey.core.impl.provider.entity.DocumentProvider
com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$General
com.sun.jersey.json.impl.provider.entity.JSONArrayProvider$General
com.sun.jersey.json.impl.provider.entity.JSONObjectProvider$General
com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
com.sun.jersey.core.impl.provider.entity.EntityHolderReader
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$General
com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General
com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy
Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java class com.foo.json.Me, and Java type class com.foo.json.Me, and MIME media type text/javascript; charset=UTF-8 was not found
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:550)
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:506)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:684)
at com.sun.jersey.api.client.WebResource.get(WebResource.java:191)
at com.foo.json.Me.main(Me.java:18)
Ответ от прокручивания URL:
$ curl --head https://graph.facebook.com/me?fields=id,name\&access_token=deleted
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Cache-Control: private, no-cache, no-store, must-revalidate
Content-Type: text/javascript; charset=UTF-8
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Pragma: no-cache
X-FB-Rev: 532491
X-FB-Debug: EGBmGLM1xfMiWi8KILCkQaG6FTn+WnRufgVY7FXDxnQ=
X-Cnection: close
Content-Length: 0
Date: Wed, 28 Mar 2012 18:58:53 GMT
и содержание:
$curl --head https://graph.facebook.com/me?fields=id,name\&access_token=deleted
{"id":"100001234567890","name":"My Name"}
Что я делаю не так?Я хочу использовать клиентскую библиотеку Джерси и предпочел бы не переключаться на другую библиотеку.Спасибо!