java - Jersey Moxy based rest service not consuming nested json post request payload -


i have snake case representation of json data '{"first_name":"michael", "last_name":"jordan", "address_loc":{"city_name":"mumbai", "street":"galino1"}}'. want consume data jersey + moxy based post method resource in form of pojo representation. please suggest.please note normal camel case representation of json working using given following code snippet have requirement of using snake case.

@xmlrootelement  public class person {  private string firstname; private string lastname;  private addressloc addressloc = new addressloc();  public person(){};  public address getaddressloc() {     return addressloc ; } public void setaddressloc(address address) {     this.addressloc = address; }  public string getfirstname() {     return firstname; } public void setfirstname(string firstname) {     this.firstname = firstname; }  public string getlastname() {     return lastname; } public void setlastname(string lastname) {     this.lastname = lastname; }  } 

child/nested class

public class addressloc {  private string cityname; private string street;  public addressloc(){};  public string getcityname() {     return cityname; } public void setcityname(string city) {     this.city = city; } public string getstreet() {     return street; } public void setstreet(string street) {     this.street = street; }  } 

resource class

   import javax.ws.rs.consumes;    import javax.ws.rs.post;    import javax.ws.rs.path;     import javax.ws.rs.produces;    import javax.ws.rs.core.mediatype;    import com.nabisoft.tutorials.jerseymoxy.model.person;  @path("/person") public class personresource {  @post @consumes({mediatype.application_json}) @produces({mediatype.text_plain}) @path("/post") public string postperson(person pers) throws exception{      system.out.println("first name = "+pers.getfirstname());     system.out.println("last name  = "+pers.getlastname());     system.out.println("last name  = "+pers.getaddress().getcity());     system.out.println("last name  = "+pers.getaddress().getstreet());      return "ok"; } } 

client code

<script src="<%=request.getcontextpath() %>/js/jquery-1.11.2.min.js"></script>     <script>         var ctxpath = "<%=request.getcontextpath() %>";         $(function(){                             $("#postperson, #postmessage").on("click", function(){                 $.ajax({                     url: $(this).attr("id") === "postmessage" ? ctxpath+"/service/message/post" : ctxpath+"/service/personwa/post",                     type: "post",                     data: '{"first_name":"michael", "last_name":"jordan", "address_loc":{"city_name":"mumbai", "street":"galino1"}}',                     contenttype: "application/json",                     cache: false,                     datatype: "json"                 });             });                         });     </script> 

apart above listed codebase have "applicationconfig.java" , "jsonmoxyconfigurationcontextresolver.java" without fancy implementaion in it. thanks.

you want add javax.xml.bind.annotation.xmlelement annotation , provide (snake case) name.

@xmlrootelement public class person {     @xmlelement(name="first_name")    private string firstname; 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -