I am working on an assignment to add a new tag to the JSON request that we are going to make a call-out. The request is below.
{
"Version": "1.0",
"RequestingSystemName": "SFORCECS",
"InsuredInformation": {
"Zipcode": "12335",
"StateProvinceCode": "CA",
"PhoneNumber": "(111) 111-2222",
"MiddleName": null,
"LastName": "ABC",
"FirstName": "DEF",
"City": "PLACEWI",
"BirthDate": "1950-01-01",
"AddressLine3": null,
"AddressLine2": null,
"AddressLine1": "111 123 Drive"
},
"BeneficiaryList": [
{
"RelationShipEnum": "Nephew",
"Relationship": 18,
"PrimaryIndicator": 0,
"Percentage": null,
"FullName": "XYZ DEQ"
},
{
"RelationShipEnum": "Niece",
"Relationship": 20,
"PrimaryIndicator": 0,
"Percentage": null,
"FullName": "DEQ XYZ"
}
],
"ApplicationInformation": {
"SignedDateTime": "2010-01-01T01:01:01.000Z",
"ProductIdentifier": "1",
"MarketingSequenceNumber": "11111111111",
"EmailAddress": null,
"ContractNumber": "1111111",
"BasicAmount": "1000",
"AgentID": "12345"
}
}
Now, my task is to change the Beneficiary info request. It should be as shown below.
"BeneficiaryList": {"Beneficiary":[
{
"RelationShipEnum": "Nephew",
"Relationship": 18,
"PrimaryIndicator": 0,
"Percentage": null,
"FullName": "XYZ DEQ"
},
{
"RelationShipEnum": "Niece",
"Relationship": 20,
"PrimaryIndicator": 0,
"Percentage": null,
"FullName": "DEQ XYZ"
}
]},
Can some one help? The apex class that generates the request for beneficiary info is below.
public class ReqBasic{
public class Beneficiary{
public Beneficiary(){}
public Beneficiary(String FullName, Integer PrimaryIndicator, Integer Percentage, Integer Relationship){
this.FullName = FullName;
this.PrimaryIndicator = PrimaryIndicator;
this.Percentage = Percentage;
this.Relationship = Relationship;
}
public Beneficiary(String FullName, String PrimaryIndicator, Integer Percentage, String Relationship){
this.FullName = FullName;
this.setPrimaryIndicatorStr(PrimaryIndicator);
this.Percentage = Percentage;
this.setRelationshipStr(Relationship);
}
}
}
I am not sure what change I need to make to add the beneficiary: tag under the BeneficiaryList. Can some one help?
The code you shared doesn't have what you need but somewhere in the request class you should have a variable called BeneficiaryList which would look like
List< Beneficiary> BeneficiaryList; //or = new List<Beneficiary>(); or Beneficiary[] depending on the coding style
You would need to make a new class called Beneficiaries (or whatever you want) which contains a List of Beneficiary
public class Beneficiaries{
List< Beneficiary> Beneficiary = new List<Beneficiary>();
public Beneficiaries(List<Beneficiary> beneficiaries){
Beneficiary.addAll(beneficiaries);
}
}
Then in your class that is the request set BeneficiaryList from a list of Beneficiary to the new Beneficiaries class
Beneficiaries BeneficiaryList = new Beneficiaries(beneficiaries);
Obviously you implmentation would depend on how your request class is setup and how you add beneficiaries but you should at least create an add(...) method so that you dont have to change too much of the code