i have created play rest app needs take input dto
json object. when trying print it, coming null on console.
my code far :
public class mobileorderdetailsrestservice extends controller { public void mobileorderdetails(@valid mobileorderdetailsinputdto dto) { //if (request.secure) { if(validation.haserrors()){ system.out.println(arrays.tostring(validation.errors().toarray())); } system.out.println(dto); //{ boolean isvaliduser = false; try { gson gson = new gsonbuilder().serializenulls().create(); mobileorderdetailsinputdto mobileorderdetailsinputdto = gson.fromjson( new jsonreader(new inputstreamreader(request.body)), mobileorderdetailsinputdto.class); stringbuffer buff = new stringbuffer(); inputstreamreader reader = new inputstreamreader(request.body); while(-1 != reader.read()){ buff.append(reader.read()); } system.out.println(buff); system.out.println(mobileorderdetailsinputdto); // isvaliduser = performlogin(); } catch (exception e) { e.printstacktrace(); } if (isvaliduser) { response.setcontenttypeifnotset("application/json"); test test = new test(); test.setname("no name"); test.setnumber(11); renderjson(test); } //} else response.status = 501; } }
so technically, object should come unless has errors, strangely errors not getting printed.
my input json , dto class is:
{ "password":"asdsa", "progid":"asda", "userid":"asdas", "documenttype":"33","orderno": "3322", "sellerorganizationcode":"2233","shipnode":"33", "shipmentno":"33"}
class:
public class mobileorderdetailsinputdto { private string password; private string progid; private string userid; private string documenttype; private string orderno; private string sellerorganizationcode; private string shipnode; private string shipmentno; public mobileorderdetailsinputdto(){ } public string getpassword() { return password; } public void setpassword(string password) { this.password = password; } public string getprogid() { return progid; } public void setprogid(string progid) { this.progid = progid; } public string getuserid() { return userid; } public void setuserid(string userid) { this.userid = userid; } public string getdocumenttype() { return documenttype; } public void setdocumenttype(string documenttype) { this.documenttype = documenttype; } public string getorderno() { return orderno; } public void setorderno(string orderno) { this.orderno = orderno; } public string getsellerorganizationcode() { return sellerorganizationcode; } public void setsellerorganizationcode(string sellerorganizationcode) { this.sellerorganizationcode = sellerorganizationcode; } public string getshipnode() { return shipnode; } public void setshipnode(string shipnode) { this.shipnode = shipnode; } public string getshipmentno() { return shipmentno; } public void setshipmentno(string shipmentno) { this.shipmentno = shipmentno; } @override public string tostring() { return "mobileorderdetailsinputdto [password=" + password + ", progid=" + progid + ", userid=" + userid + ", documenttype=" + documenttype + ", orderno=" + orderno + ", sellerorganizationcode=" + sellerorganizationcode + ", shipnode=" + shipnode + ", shipmentno=" + shipmentno + "]"; } }
please let me know if missing anything.
versions : play! 1.4.2
note: commented code https cannot enable on local.