You need to sign in to do that
Don't have an account?
How To Generate JSON Request Body from Wrapper Request Class.
I am writing a REST Service and have created Request and Response Wrappers, Finding it difficult to generate the JSON Request Body out of the wrapper classes.
Below are the Sample Classes.
public class requestResource{
public orderRequestResource order {get;set;}
}
public class orderRequestResource {
public String accountUNumber {get;set;}
public String contractNumber {get;set;}
public string status {get;set;}
public string externalKey {get;set;}
public string orderStartDate {get;set;}
public string priceBookName {get;set;}
public List<orderLineItemRequestResource> orderItems {get;set;}
}
public class orderLineItemRequestResource{
public string quantity {get;set;}
public string unitPrice {get;set;}
public string description {get;set;}
public string productCode {get;set;}
public string externalKey {get;set;}
}
Below are the Sample Classes.
public class requestResource{
public orderRequestResource order {get;set;}
}
public class orderRequestResource {
public String accountUNumber {get;set;}
public String contractNumber {get;set;}
public string status {get;set;}
public string externalKey {get;set;}
public string orderStartDate {get;set;}
public string priceBookName {get;set;}
public List<orderLineItemRequestResource> orderItems {get;set;}
}
public class orderLineItemRequestResource{
public string quantity {get;set;}
public string unitPrice {get;set;}
public string description {get;set;}
public string productCode {get;set;}
public string externalKey {get;set;}
}
If you want to populate your wrapper class properties with response data then you have to use JSON.deserialize method.
If you want to create a JSON from a class/object record then use JSON.serialize method.
I hope these examples will help you to understand the syntax.