users@jersey.java.net

[Jersey] Re: _at_Consumes with JSONObject issue

From: Pengfei Di <pengfei.di_at_match2blue.com>
Date: Thu, 14 Apr 2011 15:01:51 +0200

Hi, sudhakar

@Produces(MediaType.TEXT_PLAIN) => @Produces(MediaType.APPLICATION_JSON)


since you specified the type in your client as JSON.

Pengfei




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.


-- 
Pengfei Di
Technology
match2blue software development GmbH
Leutragraben 1
07743 Jena
Tel: +49 3641 816 8092
Mobil: +49 1520 166 8691
Fax: +49 3641 573 3479
Email: pengfei.di_at_match2blue.com
Web  : www.match2blue.com
Blog : http://blog.match2blue.com
Registergericht: Amtsgericht Jena
Registernummer: HRB 503726
Geschäftsführerin: Stephanie Renda