I have written a Restful web service API, which is accepting two different Object, Is it possible to call this api using Jersey client. I am not able to call this using Jersey client. Is this a limitation of Rest API that we can not pass multiple objects to a method.
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/hello")
public class TimePassService {
@POST
@Path("/post")
@Consumes(MediaType.APPLICATION_JSON)
public Response saveEmployeeInfo(final Employee input,final Manager input1) {
String result = "Employee saved : " + input;
System.out.println(input);
System.out.println(input1);
return Response.status(201).entity(result).build();
}
}
When I discussed this with some techies, they replied that it is not possible, The solution is to wrap these two object into a third object and then pass a single Object.
Please let me know if there is some other solution of this.
The solution is to wrap these two object into a third object and then pass a single Object. I wonder string json that post from client how does it look like?
is it this :
That is not possible. See the JAX-RS specification:
There can be only one method 'entity parameter'.
What you ask for would not be RESTful. REST ist not RPC (Remote Procedure Call), you don't 'pass' objects to a 'method'. In REST you transfer Resource representations from and to identifying URLs.
In your example the Resource would be an
EmployeeInfo
wrappingEmployee
andManager
.Besides,
/post
is not a very RESTful URL. What Resource is identified by this? What happens if youGET /post
? Please think in REST terms, not in RPC.