Skip to main content
3 of 3
added 145 characters in body
user905
  • 261
  • 6
  • 21

dynamic json body as http post request

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); } } 

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.GetUrl getUrl= new RequestWrapper.GetUrl ('url1', 'url2'); RequestWrapper.OrderDetails orderDetails = new RequestWrapper.OrderDetails('txnId', 'custId'); String jsonRequestBody = JSON.serialize(RequestWrapper.GetUrlRequest); req.setBody(jsonRequestBody); 

Error is: Constructor not defined

user905
  • 261
  • 6
  • 21