How to get raw post with jersey?

How can I get a raw POST with a jersey? @FormParam will not work because I am sending raw JSON not to any particular POST field.

+6
source share
2 answers

Jersey has a provider for mapping JSON objects to Java. To map the request body to an object, simply specify the object as an argument to the resource method. If you need raw JSON, specify an object 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) { // .... } } 
+6
source
 @POST public String handleRequest(String requestBody) { logger.info(requestBody); return "ok"; } 
+1
source

All Articles