+ Start a Discussion
Monika JhaMonika Jha 

Error : "Inner types are not allowed to have inner types" in wrapper class while parsing JSON to string in apex

The JSON format is like this
{

"GenerationTime": "20200119170533",
"ResponseCode": "MSK",
"ValidationExceptions": [
    {
        "SettlementDate": "20200113",
        "MSL": "_A",
        "MSN": {
                "ImportMSID": 1000000000059,
                "ExportMSID": null
               },
        "MRA": {
                        "SettlementPeriod": 34,
                        "DeliveredVolume": 23.21,
                        "ExceptionReason": "The import volume doesnot match with the actual allocation"
                    }
    },
    {
        "SettlementDate": "20200114",
        "MSL": "_B",
        "MSN": {
                "ImportMSID": 1000000000060,
                "ExportMSID": null
               },
        "MRA": {
                        "SettlementPeriod": 45,
                        "DeliveredVolume": 21.21,
                        "ExceptionReason": "The import volume doesnot match with the actual allocation"
                    }
    }
]
}

i wrote the wrapper class for it as
public class ExcFileWrapper{
    Public String GenerationTime; 
    Public String ResponseCode;
    Public List <ValidationExcepWrapper> ValidationExceptions; 

    public class ValidationExcepWrapper{ 
        Public String SettlementDate; //20200113"
        Public String MSL; //_A"
        public MSNWrapper MSN;
        Public MRAWrapper MRA;
    }
    public class MSNWrapper {
        Public String ImportMSID;
        Public String ExportMSID;
    }
    Public class MRAWrapper{
        Public integer SettlementPeriod;
        Public decimal DeliveredVolume;
        Public String ExceptionReason;
    }
}

After searching i found this is the correct way to write wrapper class for the JSON. But getting error as "Inner types are not allowed to have inner types". Where can i make change to eliminate this error?
Best Answer chosen by Monika Jha
Prady01Prady01
Hi there, You can actually use a tool to which will give you and apex class based on your input JSON. Below is the link.

https://json2apex.herokuapp.com/

Hope this helps!
Prady01