users@jersey.java.net

[Jersey] Re: _at_Consumes with JSONObject issue

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Fri, 29 Apr 2011 12:15:17 +0200

Hello Sudhakar,

We provide support for org.codehaus.jettison.json.JSONObject
as part of our jersey-json module. I guess it is the "same" class,
only in a different package.

If you can, you may want to switch to using that jettison
based JSONObject. If not, you can get inspired at [1]
on how to write your own Message Body readers/writers.
Look at the com.sun.jersey.json.impl.provider.entity.JSONObjectProvider
class.

HTH,

~Jakub

[1]http://download.java.net/maven/2/com/sun/jersey/jersey-json/1.6/jersey-json-1.6-sources.jar

On 04/14/2011 01:55 PM, sudhakar wrote:
> 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.
>