You need to sign in to do that
Don't have an account?
Wrapper Class with two inner classes (child) and how to pass to JSON Serialize and Deserialize
Hi,
At a high level, I have two different objects (not related) that I want to pass data from each to a customized service using JSON. I am currently doing that with a single object but now I need to add a second. I have built what I thought could be a good visual example but keep in mind that I am not using account and contact but the user object and custom metadata setting as the two objects but this should give a concept that hopefully you could help me with a code snippet or something from mine below that could get an example done.
Could I get this to work where it provides a list of list or something like that and I pass it into the JSON serialized method; as mentioned I do this with a single list of users currently. Again I just through something below together to give context but it uses accounts and contacts.
Bottomline, I need to pass to JSON serialize two different object records and deserialize them on the service side. Any help, examples would be appreciated.
public class WrapperMain {
public static List<AccountWrapper> awList = new List<AccountWrapper>();
public static List<ContactWrapper> cwList = new List<ContactWrapper>();
{
for (Account a : [SELECT Name FROM Account LIMIT 1]) {
AccountWrapper aw = new AccountWrapper();
aw.Name = a.Name;
awList.add(aw);
}
for (Contact c : [SELECT Name FROM Contact LIMIT 1]) {
ContactWrapper cw = new ContactWrapper();
cw.Name = c.Name;
cwList.add(cw);
}
}
private class AccountWrapper {
public String Name {get; set;}
}
private class ContactWrapper {
public String Name {get; set;}
}
}