WEB Service in Java

1

I'm creating a Web Service, but I'm wondering how to get JSON in it as a parameter.

@Path("WebService/{json}")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String  POST (@PathParam("json") String json) 
{
    return json ;
}

In this code I'm getting JSON in the URL like this:

http://localhost:8080/IC/webresources/WebService/[   {     "name": "SAM",     "id": 1   },   {     "name": "DEAN",     "id": 2   } ]

That is, there is a JSON in the URL.

That's the only way I've found it so far. Can someone give me a light?

    
asked by anonymous 31.12.2016 / 19:06

2 answers

1

Use @FormParam instead of @PathParam .

With this, you can put the JSON in the body of the request, since this is a POST.

    
31.12.2016 / 19:28
-1

You do not need to pass the parameters through the URL, since this is a POST.

See the example on this link link in the POST part.

See that your

  

@Path ("WebService / {json}")

It will be different without json.

I hope I have helped.

    
31.12.2016 / 19:16