This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Web Services and the fly likes Sending and Retrieving JSON data from Jersey API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Sending and Retrieving JSON data from Jersey API" Watch "Sending and Retrieving JSON data from Jersey API" New topic

Sending and Retrieving JSON data from Jersey API

Ayan Biswas
Ranch Hand

Joined: Jul 10, 2010
Posts: 104
I am trying to send JSON object to and from a restful webservice implemented through a Jersey API
Here is my code for the service

Here is my code for the client

But this shows the following error

Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class java.lang.Class, and MIME media type, application/octet-stream, was not found

Can anybody help?Is there any tutorial that explains how to do this?

H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 471
While looking for my issue Providers and MessageBodyWriter, I came across this article.
Hope it help if you read it.
kiran kanaparthi

Joined: Dec 16, 2011
Posts: 2
Here is the Server Side Code

public Response createTrackInJSONFormString(String trackName) {
String result = "Track saved : " + trackName;
System.out.println("trackname from the User is : "+ trackName+" and result"+result);
Gson gson = new Gson();
Person person = new Person();
person.setAddress("123 Main Street");
String jsonString = gson.toJson(person);
System.out.println("This is the messagePost from Jersey Service SERVICE_NAME is 333333 /post/withresponse/onlystring");
return Response.status(201).entity(jsonString).build();


Here is the Sample JSP Client
<form id="postFormThree" action="./rest/shade/post/withresponse/onlystring"
<input type="text" name="trackName" value="onlyStringStrackNameONLY">
<input type="submit" name="submitPost" value="submitPost-FORM-postFormThree" />

Both were working when I tested them on Jersey-bundle-1.16
I agree. Here's the link:
subject: Sending and Retrieving JSON data from Jersey API
It's not a secret anymore!