I want to use AngularJs in a my page to filter a list of records, i found this article very helpful. the problem is in the article, the JSON.serialize is applied on a list like this

 public static String getlstAccount() {
     return JSON.serialize([SELECT Id, Name, Type, Phone FROM Account limit 10]);

what i want is to send a wrapper class instead of a list and i do not know how to use this fonction to achieve this , can it be like that ?

public static String getWrapperList() {
         return JSON.serialize(WrapperList);

where WrapperList is wrapper class that i created.

any help ?

  • are you having any issue with this? IMO you can serialize this way too.
    – Mr.Frodo
    Jul 6, 2016 at 9:21
  • I did not try it yet , but it sounds very simplistic to do it like that, i will try it now Jul 6, 2016 at 12:55

1 Answer 1


You can use this code for wrapping your account list

public static string getWrappedAccountList() {
    //Assuming you wrapper class name is 'Wrapper'
    List<Wrapper> WrapperList = new List<Wrapper>();

    for(Account account : [SELECT Id, Name, Type, Phone FROM Account limit 10]) {
        Wrapper wrap = new Wrapper();
        wrap.name = account.name;
        wrap.Type = account.Type;
        wrap.Phone = account.Phone;


    return JSON.serialize(WrapperList);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .