Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7745867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:07:52+00:00 2026-06-01T10:07:52+00:00

My code is not working: 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

  • 0

My code is not working:

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);
    }

}

The error is:

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)

The response from curl-ing the URL is:

$ 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

and the content is:

$curl --head https://graph.facebook.com/me?fields=id,name\&access_token=deleted
{"id":"100001234567890","name":"My Name"}

What am I doing wrong? I do want to use the Jersey Client library and would prefer not to have to switch to another library. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:07:54+00:00Added an answer on June 1, 2026 at 10:07 am

    You just have to mention Accept header of the response to application/json as it is coming as json.
    In absence of it, it is treated as text/javascript response(check headers of your curl response) which is giving you ClientHandlerException.

    Running code:

    TestClient.java

    public class TestClient {
    
        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");
            MyBean response=web_resource.accept(MediaType.APPLICATION_JSON).get(MyBean.class);
            System.out.println(response.getId());
        }
    
    }
    

    MyBean.java

    @XmlRootElement
    public class MyBean{
    
        String id;
        String name;
    
        public String getId() {
            return id;
        }
        public void setId(String id) {
            this.id = id;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why is the following code not working? if(EventLog.Exists(Foo)) { EventLog.Delete(Foo); } if(EventLog.Exists(Foo) == false)
can anybody tell me why is the following code not working? <script type=text/javascript src=../../Scripts/jquery.js></script>
i am using python 2.5.2 . The following code not working. def findValue(self, text,
The code seems not working. // $counter is an instance of Zend_Db_Table_Abstract $counter->update(array('hits' =>
I'm not sure why my code is not working.. I have code in vba
runat=server /> But this code is not working How can I add multiple controls
can somebody tell me why my code is not working? class Connection { public
Any idea why the following code is not working mysql credentials are correct, have
I want to display data from database in DataGridView...This is my code...Its not working...Can
I have code for simple audio player on android. But it is not working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.