I am trying to call a jersey restful web service from android. My android code is
Client code:
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost("http://X.X.X.X:8080/RestfulService/rest/post");
post.setHeader("content-type", "application/json");
JSONObject dato = new JSONObject();
dato.put("email", email);
dato.put("password", password);
StringEntity entity = new StringEntity(dato.toString());
post.setEntity(entity);
HttpResponse resp = httpClient.execute(post);
String rs = EntityUtils.toString(resp.getEntity());
return rs
Webservice code
@POST
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
public String AuthMySQL(JSONObject json) {
String password = (String) json.get("password");
String email = (String) json.get("email");
*I am using the string values to get the result from the database*
}
The error i get is something like com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java type, class org.json.JSONObject.... and MIME media type, application/json was not found.
Your help is much appreciated
This occurs when you don't have the correct libraries included to properly map the json to a POJO or there is not an appropriate POJO for the input.
Look at adding the jersey-json maven dependency to your project