Please see the below code I have done some modification,
@RestResource(urlMapping='/instructionsRestCall/*') global with sharing class InstructionsRestService { @HttpGet global static List getInstructions(){
RestRequest request = RestContext.request;
RestResponse response = RestContext.response;
String instId = request.requestURI.subString(request.requestURI.lastIndexOf('/'));
//Send list of Instruction details as per the provided JSON format for Instruction records where Category Type Code (catTypeCd__c) is not null
List<Instructions__c> instList = [select Country__c,Category__c,SubCategory__c,Requirements__c,catTypeCd__c from Instructions__c];
system.debug('Instructions List->>>>'+instList);
List<requestTypes> catWrapList = new List<requestTypes>();
List<countryWrapper> counWrapList = new List<countryWrapper>();
for(Instructions__c ins : instList){
if(ins.catTypeCd__c != null){
countryWrapper countWrap = new countryWrapper();
requestTypes catWrap = new requestTypes();
caseTypes innWrap = new caseTypes();
countWrap.corpCode = ins.Country__c;
catWrap.name = ins.Category__c;
innWrap.name = ins.SubCategory__c;
innWrap.value = ins.Requirements__c;
innWrap.categoryTypeCode = ins.catTypeCd__c;
countWrap.requestTypes = catWrap;
// countWrap.innerWrapper = innWrap;
countWrap.requestTypes.caseTypes = innWrap;
counWrapList.add(countWrap);
}
}
system.debug('Result from WrapperList->>>>'+counWrapList);
return counWrapList;
//return JSON.serialize(counWrapList);
}
global class countryWrapper{
public String corpCode{get;set;}
public requestTypes requestTypes{get;set;}
//public innerWrapper innerWrapper{get;set;}
}
global class requestTypes{
public String name{get;set;}
public caseTypes caseTypes{get;set;}
}
global class caseTypes{
public String name{get;set;}
public String value{get;set;}
public Double categoryTypeCode{get;set;}
}
}
I want this this corpCode will be in first position and after that requestType. What is wrong with my wrapper. Thanks in advance,