0

I have a Json Object which I created with the online JSON to apex tool. This works a a separate class how can i make this a subclass. I get the error:

Inner types are not allowed to have inner types

How do I refactor this to not have innertypes within innertypes?

Apex

global with sharing class mainclass {
  public class SalesProductJSON{
    public String ProductCode;  //
    public String ProductName;  //
    public cls_SalesProductSections[] SalesProductSections;
    class cls_SalesProductSections {
        public String SectionCode;  //
        public String SectionName;  //
        public cls_SalesProductItems[] SalesProductItems;
    }
    class cls_SalesProductItems {
        public String ItemCode; //
        public String ItemName; //
    }
    public static List<salesProductJSON> parse(String json){
        return (List<salesProductJSON>) System.JSON.deserialize(json, List<salesProductJSON>.class);  
    }
}
}
2
  • 2
    Why does it need to be an inner class? Note inner class != subclass.
    – David Reed
    Feb 28, 2020 at 15:47
  • @DavidReed My requirement is to have all functionality in one class
    – Thomas
    Feb 28, 2020 at 15:52

1 Answer 1

6

Just pull the definitions out of the class:

global with sharing class mainclass { 
  class cls_SalesProductSections { 
    public String SectionCode; // 
    public String SectionName; // 
    public cls_SalesProductItems[] SalesProductItems; 
  } 
  class cls_SalesProductItems { 
    public String ItemCode; // 
    public String ItemName; //
  }
  public class SalesProductJSON{ 
    public String ProductCode; // 
    public String ProductName; // 
    public cls_SalesProductSections[] SalesProductSections; 
    public static List<salesProductJSON> parse(String json){ 
      return (List<salesProductJSON>) System.JSON.deserialize(json, List<salesProductJSON>.class); 
    } 
  } 
}

You must log in to answer this question.

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