How can I get the raw POST with Jersey? @FormParam
won't work because I'm posting raw JSON not in any specific POST field.
Jersey comes with a provider for mapping JSON to Java objects. To map your request body to an object simply specify that object as an argument to your resource method. If you want the raw JSON, specify the object to be of type java.lang.String
.
@Path("/mypath")
public class MyResource {
/**
* @param pojo Incoming request data will be deserialized into this object
*/
@POST
@Path("/aspojo")
@Consumes(MediaType.APPLICATION_JSON)
public Response myResourceMethod(MyPojo pojo) {
// ....
}
/**
* @param json Incoming request data will be deserialized directly into
* this string
*/
@POST
@Path("/asjson")
@Consumes(MediaType.APPLICATION_JSON)
public Response myResourceMethod(String json) {
// ....
}
}
@POST
public String handleRequest(String requestBody) {
logger.info(requestBody);
return "ok";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With