0

I am passing an Employee Object Form Client in RestFul webservices Jaxrs2/jersy2

 @GET
    @Path("{empObj}")
    @Produces(MediaType.APPLICATION_XML)
    public Response readPK(@PathParam("empObj")Employee empObj) {
        //do Some Work
        System.out.println(empObj.getName());
        return Response.status(Response.Status.OK).entity(result).build();
    }

how can achive this object using GET method?? thanx in advance

java baba
  • 2,199
  • 13
  • 33
  • 45

1 Answers1

1

By using @PathParam on a method parameter / class field you're basically telling JAX-RS runtime to inject path segment (usually string) to your (String) parameter. If you're sending an object (Employee) representation directly via your URI (query param, path param) you should also provide ParamConverterProvider. Beware that this is not possible in some situation and it's not a recommended practice. However, if you're sending the object from client to server in message body, simply remove @PathParam and MessageBodyReader will take care of converting input stream to your type:

@GET
@Path("{empObj}")
@Produces(MediaType.APPLICATION_XML)
public Response readPK(Employee empObj) {
    //do Some Work
    System.out.println(empObj.getName());
    return Response.status(Response.Status.OK).entity(result).build();
}
Michal Gajdos
  • 10,339
  • 2
  • 43
  • 42