I am trying to pass multiple entities to the web service method. The web service method has two parameters of pojo entity type. I am able to post only one entity to the web service method. I am unable to post multiple entities to the web service method.
Server side code:
@POST
@Path("/test")
@Produces(MediaType.APPLICATION_XML)
@Consumes(MediaType.APPLICATION_XML)
public void testMethod(Emp emp, Student stud){
...
}
Client side code:
...
...
Emp emp = new Emp;
Student stud = new Student();
ClientResponse response = resource.type(MediaType.APPLICATION_XML).entity(emp).entity(stud).post(ClientResponse.class);
A request can only have one entity body, that's why the restriction. The only option I can think of is to use multipart request, where you can have multiple body parts.
Example server side
Client side
Result:
Jersey dependency for multipart support.