Skip to main content
added 145 characters in body
Source Link
user905
  • 261
  • 6
  • 21
public class RequestWrapper { public static GetUrlRequest GetUrlRequest; public class abcOrderDetails { public String ab;txnId; public String cd;custOrder; public abcOrderDetails(String tdtxnId, String cRcustOrder){ this.abtxnId = tId;txnId; this.cdcustOrder = cR;custOrder; } } public class GetUrlRequest { public String cd;custId; public String sb;custCode; public String pp;purpose; public abcOrderDetails aO;orderDetails; public cblGetUrl cO;getUrl; public GetUrlRequest(String cIdcustId, String sBCcustCode, String purpurpose, abcOrderDetails abcInstanceorderDetails, cblGetUrl cblInstancegetUrl){ cdcustId = cId;custId; sbcustCode = sBC;custCode; pppurpose = pur;purpose; abcorderDetails = abcInstance;orderDetails; cblgetUrl = cblInstance;getUrl; } } public class cblGetUrl { public String ru;url1; public String cu;url2; public cbl(String rUrlurl1, String cUrlurl2){ this.ruurl1 = rUrl;url1; this.cuurl2 = cUrl;url2; } } public static RequestWrapper parse(String json) { return (RequestWrapper) System.JSON.deserialize(json, RequestWrapper.class); } } 
RequestWrapper.cbl cblInstanceGetUrl =getUrl= new RequestWrapper.cblGetUrl ('stringcblValue''url1', 'stringcuvalue''url2'); RequestWrapper.abcOrderDetails abclInstanceorderDetails = new RequestWrapper.abcOrderDetails('somestringvalue''txnId', 'somestringvalue''custId'); String jsonRequestBody = JSON.serialize(RequestWrapper.GetUrlRequest); req.setBody(jsonRequestBody); 
public class RequestWrapper { public static GetUrlRequest GetUrlRequest; public class abc { public String ab; public String cd; public abc(String td, String cR){ this.ab = tId; this.cd = cR; } } public class GetUrlRequest { public String cd; public String sb; public String pp; public abc aO; public cbl cO; public GetUrlRequest(String cId, String sBC, String pur, abc abcInstance, cbl cblInstance){ cd = cId; sb = sBC; pp = pur; abc = abcInstance; cbl = cblInstance; } } public class cbl { public String ru; public String cu; public cbl(String rUrl, String cUrl){ this.ru = rUrl; this.cu = cUrl; } } public static RequestWrapper parse(String json) { return (RequestWrapper) System.JSON.deserialize(json, RequestWrapper.class); } } 
RequestWrapper.cbl cblInstance = new RequestWrapper.cbl('stringcblValue', 'stringcuvalue'); RequestWrapper.abc abclInstance = new RequestWrapper.abc('somestringvalue', 'somestringvalue'); String jsonRequestBody = JSON.serialize(RequestWrapper.GetUrlRequest); req.setBody(jsonRequestBody); 
public class RequestWrapper { public static GetUrlRequest GetUrlRequest; public class OrderDetails { public String txnId; public String custOrder; public OrderDetails(String txnId, String custOrder){ this.txnId = txnId; this.custOrder = custOrder; } } public class GetUrlRequest { public String custId; public String custCode; public String purpose; public OrderDetails orderDetails; public GetUrl getUrl; public GetUrlRequest(String custId, String custCode, String purpose, OrderDetails orderDetails, GetUrl getUrl){ custId = custId; custCode = custCode; purpose = purpose; orderDetails = orderDetails; getUrl = getUrl; } } public class GetUrl { public String url1; public String url2; public cbl(String url1, String url2){ this.url1 = url1; this.url2 = url2; } } public static RequestWrapper parse(String json) { return (RequestWrapper) System.JSON.deserialize(json, RequestWrapper.class); } } 
RequestWrapper.GetUrl getUrl= new RequestWrapper.GetUrl ('url1', 'url2'); RequestWrapper.OrderDetails orderDetails = new RequestWrapper.OrderDetails('txnId', 'custId'); String jsonRequestBody = JSON.serialize(RequestWrapper.GetUrlRequest); req.setBody(jsonRequestBody); 
deleted 1 character in body
Source Link
user905
  • 261
  • 6
  • 21
RequestWrapper.cbl cblInstance = new RequestWrapper.cbl('stringcblValue', 'stringcuvalue'); RequestWrapper.abc abclInstance = new RequestWrapper.abc('somestringvalue', 'somestringvalue'); String jsonRequestBody = JSON.serialize(RequestWrapper.GetUrlRequest); req.setBody(jsonRequestBody); 

Error is: Method doesConstructor not exist or incorrect signature: void cbl(String, String) from the type RequestWrapperdefined

RequestWrapper.cbl('stringcblValue', 'stringcuvalue'); RequestWrapper.abc('somestringvalue', 'somestringvalue'); String jsonRequestBody = JSON.serialize(RequestWrapper.GetUrlRequest); req.setBody(jsonRequestBody); 

Error is: Method does not exist or incorrect signature: void cbl(String, String) from the type RequestWrapper

RequestWrapper.cbl cblInstance = new RequestWrapper.cbl('stringcblValue', 'stringcuvalue'); RequestWrapper.abc abclInstance = new RequestWrapper.abc('somestringvalue', 'somestringvalue'); String jsonRequestBody = JSON.serialize(RequestWrapper.GetUrlRequest); req.setBody(jsonRequestBody); 

Error is: Constructor not defined

Post Undeleted by user905
Post Deleted by user905
Source Link
user905
  • 261
  • 6
  • 21

dynamic json body as http post request

public class RequestWrapper { public static GetUrlRequest GetUrlRequest; public class abc { public String ab; public String cd; public abc(String td, String cR){ this.ab = tId; this.cd = cR; } } public class GetUrlRequest { public String cd; public String sb; public String pp; public abc aO; public cbl cO; public GetUrlRequest(String cId, String sBC, String pur, abc abcInstance, cbl cblInstance){ cd = cId; sb = sBC; pp = pur; abc = abcInstance; cbl = cblInstance; } } public class cbl { public String ru; public String cu; public cbl(String rUrl, String cUrl){ this.ru = rUrl; this.cu = cUrl; } } public static RequestWrapper parse(String json) { return (RequestWrapper) System.JSON.deserialize(json, RequestWrapper.class); } } 

I formed this class for the json body that I need to pass in my http post request. I created this class from json generator and added the constructors. can someone please tell me how do I initialize this class, I will be setting dynamic values to this later, but right now I want to hardcode values to this class vars and send it as the request body.

I tried to as follows but this gives me error:

RequestWrapper.cbl('stringcblValue', 'stringcuvalue'); RequestWrapper.abc('somestringvalue', 'somestringvalue'); String jsonRequestBody = JSON.serialize(RequestWrapper.GetUrlRequest); req.setBody(jsonRequestBody); 

Error is: Method does not exist or incorrect signature: void cbl(String, String) from the type RequestWrapper