0

I need to retrieve the json text input of the body of the post request..

I use javax.ws.rs.*

This is my code ..:

 
    @POST
    @Consumes(value = MediaType.APPLICATION_JSON)
    @Produces(MediaType.TEXT_PLAIN)
    public Response postProduct(final Product product)
    {
        try
        {
             
        // I want to retrieve the json text of the post request body here.
            if (null == product) // In case of an empty "product"
            {
                return Response.status(Response.Status.BAD_REQUEST).entity("No data").build();
            }
            ....

This is the json body that I want to retrieve in my method :

   {
   "productNumber":"65421",
   "ExpirationDate":"2023-12-31",
   "supplier":"yyy"
   } ```


Thanks a lot in advance..
  • Hello Najlae, welcome to StackOverflow! What does the Product object contain? Your issue is that you do not know how to extract data from the Product object. Could you share documentation/code on the product object? Where does product come from? – Florian Fasmeyer Jan 27 '23 at 01:26
  • You may want to reformat the title to be a question: "How to read json file from a post-request in Java?" Just by formatting the title, google gives me lemons(this might be your answer): https://stackoverflow.com/questions/53340128/how-to-perform-a-post-request-using-json-file-as-body – Florian Fasmeyer Jan 27 '23 at 01:28

0 Answers0