You need to sign in to do that
Don't have an account?

Create JSON for wrapper class
Hi
I am using code like below
@RestResource(urlMapping='/test/*')
global with sharing class ClassA
{
@HttpPost
global static void createSomething(Wrapper1 req)
{
System.debug('###stringVar1 :' + req.stringVar1);
System.debug('###stringVar2:' + req.stringVar2);
System.debug('###Wrapper2:' + req.Wrapper2);
Object__c obj = new Object__c();
obj.fld1 = req.stringVar1;
obj.fld2 = req.stringVar2; insert obj;
List<Object2__c> surveyQuestionsRespList = new List<Object2__c>();
for(Wrapper2 question : req.Wrapper2)
{
Object2__c obj2 = new Object2__c();
obj2.fld4 = question.response;
obj2.fld3 = question.someId;
obj2.Object__c = obj.Id;
surveyQuestionsRespList.add(obj2);
}
insert surveyQuestionsRespList;
}
global with sharing class Wrapper1
{
public String stringVar1{get;set;}
public String stringVar2{get;set;}
public List<Wrapper2> Wrapper2{get;set;}
}
global with sharing class Wrapper2
{
public String someId{get;set;}
public String response{get;set;}
}
}
Please help me how to generate JSON for this class. Thanks in Advance.
Regards
Venkat.
I am using code like below
@RestResource(urlMapping='/test/*')
global with sharing class ClassA
{
@HttpPost
global static void createSomething(Wrapper1 req)
{
System.debug('###stringVar1 :' + req.stringVar1);
System.debug('###stringVar2:' + req.stringVar2);
System.debug('###Wrapper2:' + req.Wrapper2);
Object__c obj = new Object__c();
obj.fld1 = req.stringVar1;
obj.fld2 = req.stringVar2; insert obj;
List<Object2__c> surveyQuestionsRespList = new List<Object2__c>();
for(Wrapper2 question : req.Wrapper2)
{
Object2__c obj2 = new Object2__c();
obj2.fld4 = question.response;
obj2.fld3 = question.someId;
obj2.Object__c = obj.Id;
surveyQuestionsRespList.add(obj2);
}
insert surveyQuestionsRespList;
}
global with sharing class Wrapper1
{
public String stringVar1{get;set;}
public String stringVar2{get;set;}
public List<Wrapper2> Wrapper2{get;set;}
}
global with sharing class Wrapper2
{
public String someId{get;set;}
public String response{get;set;}
}
}
Please help me how to generate JSON for this class. Thanks in Advance.
Regards
Venkat.
Please check below post for JSON to APEX.
1) http://json2apexengine.somee.com/
2) https://www.adminbooster.com/tool/json2apex
Let us know if this will help you
Thanks
Amit Chaudhary
All Answers
Please check below post for JSON to APEX.
1) http://json2apexengine.somee.com/
2) https://www.adminbooster.com/tool/json2apex
Let us know if this will help you
Thanks
Amit Chaudhary
Thank You! It is working fine.
Thanks
Venkat.