java - JSON Response Object has additional name/value pair -
i using rest post service (using jersey 1.19) create new session details.
this code:
@post @path("/createsession") @consumes(mediatype.application_json) @produces(mediatype.application_json) public response createsession(string json) throws jsonexception{ jsonobject jsonobject = new jsonobject(json); system.out.println("json object is: " + jsonobject); string customercif = jsonobject.optstring("cif"); system.out.println("cif request is: " + customercif); sessioninfo sessioninfo = new sessioninfo(customercif); return response.ok(sessioninfo,mediatype.application_json).build(); } my request body looks this:
{ "cif": "786" } the sessioninfo object should return is:
@xmlrootelement public class sessioninfo { @xmlelement(name="sessionid") public static uuid sessionid; @xmlelement(name="cif") public string cif; //todo: transaction list added here @xmlelement(name="transactions") public string transactions; @xmlelement(name="owner") public string owner; @xmlelement(name="createdby") public string createdby; @xmlelement(name="createdtime") public string createdtime; @xmlelement(name="status") public string status; public sessioninfo(string cif){ sessioninfo.sessionid = uuid.randomuuid(); this.cif = cif; //this.transactions = null; this.owner = "owner"; this.createdby = "ownerrest"; dateformat dateformat = new simpledateformat("yyyy/mm/dd"); this.createdtime = dateformat.format(new date()); this.status = "p"; } } the output is:
{ cif: "786" owner: "owner" createdby: "ownerrest" createdtime: "2015/09/30" status: "p" sessionid: "37249cfe-4fdd-4d6c-9a4a-8b868ff2c781" cif: "786" } i don't understand why additional cif:786 @ end of response.
any pointers?
regards ali.
Comments
Post a Comment