I have a webservice and I want to send a JSON string to it through the POST method.
Until now the webservices that I have made used the GET method and looked like this:
@GET
@Produces("application/json")
@Path("{name}")
public String getJson(@PathParam("name") String name) {
//TODO return proper representation object
CompanyDatabase cmpdb=new CompanyDatabase();
String json=cmpdb.searchAgent(name);
return json;
}
What changes do I need to make to this method so that it accepts POST data?
To accept input data your method needs to declare what it consumes not produces.
The Customer class needs to be annotated properly to convert JSON to a Java POJO. It’s good practise to use the JAX-RS constants for the MediaTypes.
You should also consult the documentation for your JAX-RS provider (eg: RESTEasy or Jersey) as those user guides will probably have examples.