Quantcast
Channel: DevOps tips & tricks
Viewing all articles
Browse latest Browse all 181

JAX-RS read JSON POST body parameters

$
0
0

 Set a Response Body in JAX-RS

https://www.baeldung.com/jax-rs-response

 

 Read JSON directly


    @POST
    @Path("listwrapper/")
    @Consumes({MediaType.APPLICATION_JSON})
    @Produces({MediaType.APPLICATION_JSON})
    public String getListViaWrapperHTTPRequest(List<String> list) {

        System.out.println("getListViaWrapperHTTPRequest");

        for(String param: list){
            System.out.println("
param=" + param);
        }
        return "SOME_RESPONSE";
    }




Read HTTP request body


    @POST
    @Path("listraw/")
    @Consumes({MediaType.APPLICATION_JSON})
    @Produces({MediaType.APPLICATION_JSON})
    public String getListViaRawHTTPRequest(@Context HttpServletRequest request, byte[] bodyBytes) {

        System.out.println("getListViaRawHTTPRequest");

        System.out.println("Content-Type: " + request.getContentType().toString());

        String body = new String(bodyBytes);

        System.out.println("body=" + body);

       return "SOME_RESPONSE";

    }

Viewing all articles
Browse latest Browse all 181

Trending Articles