I'm struggling with my restful webservice (Java & Netbeans 8.2)
My method looks like:
@POST
@Path("/usedPacking")
@Consumes(MediaType.APPLICATION_JSON)
public void setUsedPackage( ??? ) {
???
}
Actually I would like to receive a json-message as post-data like: {"PackageID":"12345","Used":"false"}
My question is: What do I have to replace the "???" with?
For GET-Methods it is:
@QueryParam("ID") String input
Which allows me to access the variable specified as ID by using input.
Everything I've found so far didn't quite address the problem I face..
For a JAXRS webservice you can create an annotated class that maps to your json eg
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Package {
private String packageID;
private Boolean used;
// getters and setters here
}
then ??? will be your class
public void setUsedPackage(Package package)
When you post your json you'll need to specify the Content-type header as application/json
Here's a jaxrs tutorial I found that may help
http://www.logicbig.com/tutorials/java-ee-tutorial/jax-rs/post-example/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.