java - Custom object input for CXF-JaxRS WebClient -


i pretty new restful, , trying create sample services achieve post on void methods. able test method string class getting exception while testing custom object.

serviceclass:

@override @post @path("/sayhello") public void sayhello(person person) {     system.out.println("hello there, " + person.getname());          }  @override @post @path("/sayhi") public void sayhi(string name) {     system.out.println("hey there, " + name);        }    

test clients:

public void testsayhellorest() throws exception {      webclient client = webclient.create("http://localhost:8080/servicestutorial/sampleservice/sayhello");     person p = new person();     p.setname("my name");                client.post(p);    }  public void testsayhi() throws exception {         webclient client = webclient.create("http://localhost:8080/servicestutorial/sampleservice/sayhi");       client.post("my name");  } 

second test simple string input passes, first test fails below exception

org.apache.cxf.interceptor.fault: .no message body writer has been found class : class com.wk.services.data.person, contenttype : application/xml. 

person class

public class person {     private string name;      public string getname() {         return name;     }      public void setname(string name) {         this.name = name;     }        } 

you need annotate person class this:

@xmlrootelement(name="person") @xmlaccessortype(xmlaccesstype.public_member) public class person {     private string name;      @xmlelement (name = "name")     public string getname() {         return name;     }      public void setname(string name) {         this.name = name;     }        } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -