WEB Service in Java

Asked

Viewed 446 times

1

I’m creating a Web Service, but I’m having a lot of doubts about how to receive JSON 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 the JSON in the URL this way:

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 so far. Someone can give me a light?

2 answers

1

Use @FormParam in place of @PathParam.

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

  • Thank you, Victor! Do you have any example of request? Excuse is that it is my first time doing a Web Service.

-1

  • Thank you for your help! From what I understand it received and automatically converted to object, but in my case, I need to receive the entire JSON, without converting ... has some hint?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.