Passing an object to a REST Web Service using Jersey

前端 未结 5 752
无人共我
无人共我 2020-12-17 04:04

I have a simple WS that is a @PUT and takes in an object

@Path(\"test\")
public class Test {

    @PUT
    @Path(\"{nid}\"}
    @Consumes(\"appl         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-17 04:31

    Try this it will work

    Server Side:

    @PUT
    @Consumes(MediaType.APPLICATION_XML)
    @Produces(MediaType.APPLICATION_XML)
    public String addRecord(CustomClass mCustomClass)
    {
        ///
        ///
        ///
        return "Added successfully : "+CustomClass.getName();
    
    }// addRecord
    

    Client Side:

    public static void main(String[] args)
    {
        ///
        ///
        ///
        CustomClass mCustomClass = new CustomClass();
        Client client = ClientBuilder.newClient();
        String strResult = client.target(REST_SERVICE_URL).request(MediaType.APPLICATION_XML).put(Entity.xml(mCustomClass), String.class);
    }
    

提交回复
热议问题