How to get raw POST with Jersey?
jersey, post
Solution
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) {
// ....
}
}
Problem
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.