users@jersey.java.net

[Jersey] _at_Consumes with JSONObject issue

From: sudhakar <sudhakar.dunaka_at_tcs.com>
Date: Thu, 14 Apr 2011 04:55:22 -0700 (PDT)

Hi,

i am trying to post a JSonObject to REST Service,but i am not able to do
this.while i am running my client program i am getting following exception

com.sun.jersey.api.client.ClientHandlerException: A message body reader for
Java class net.sf.json.JSONObject, and Java type class
net.sf.json.JSONObject, and MIME media type, application/json, was not found

here is my restservice :

        import javax.ws.rs.*;
        import javax.ws.rs.ext.Provider;
        import javax.ws.rs.core.MediaType;

        import net.sf.json.JSONObject;

        @Provider
        @Path("/hello")
        public class Hello {

        @POST
        @Consumes("application/json")
        @Produces(MediaType.TEXT_PLAIN)
        public String processMessageObject(JSONObject obj) {
                        
                   return ("Success");
                }
       }

here is my client program :

public class RestJerseyClient {
        
        public static void main(String[] args) {
             JSONObject obj=new JSONObject();
                
                obj.put("ToAddr", "to_at_tcs");
                obj.put("FromAddr", "from_at_tcs");
               try{
                        
                        ClientConfig config = new DefaultClientConfig();
                       Client client = Client.create(config);
                        WebResource service = client.resource(getBaseURI());

                    System.out.println("JSON :
"+service.path("rest/hello").type(MediaType.APPLICATION_JSON).post(JSONObject.class,obj));
              }
                catch(Exception e)
                {
                        e.printStackTrace();
                }
                
        }

help me its very urgent

--
View this message in context: http://jersey.576304.n2.nabble.com/Consumes-with-JSONObject-issue-tp6272459p6272459.html
Sent from the Jersey mailing list archive at Nabble.com.