I am trying to parse a nested JSON and have generated the apex code using JSON2Apex as below:
global with sharing Class ServiceUpdates
{
@HttpPost
global static void updateservice()
{
RestRequest r = RestContext.request;
String jsonRequest = r.requestBody.toString();
JSON2Apex wscall = (JSON2Apex)JSON.deserialize(jsonRequest, JSON2Apex.class);
or ServiceUpdates.JSON2Apex wscall = (ServiceUpdates.JSON2Apex)JSON.deserialize(jsonRequest, ServiceUpdates.JSON2Apex.class);
or ServiceUpdates wscall = (ServiceUpdates)JSON.deserialize(jsonRequest, ServiceUpdates.class);
System.debug('response' +wscall );
}
public class JSON2Apex
{
public class Services {
public List<Service> Service;
}
public List<Subscriptions> Subscriptions;
public class Attribute {
public String name;
public String value;
}
public class Subscriptions {
public Subscription Subscription;
}
public class Service {
public Attribute attribute;
}
public class Subscription {
public String SAPOrder;
public String RequestType;
public String OrderStatus;
public List<Services> Services;
}
}
}
I'm getting error that Inner types are not allowed to have inner types If I remove the outer-most class from auto generated code and add in existing class then I get NULL in inner object in parsing. Can someone please help how to structure code to parse the json?
UPDATED JSON DETAILS:
{
"Subscriptions": [
{
"Subscription": {
"SAPOrder": "SAP123",
"RequestType": "New",
"OrderStatus": "0",
"Services": [
{
"Service": [
{
"attribute": {
"name": "Resilience",
"value": "Terminated"
}
},
{
"attribute": {
"name": "Number",
"value": "1234"
}
},
{
"attribute": {
"name": "serviceStartDate",
"value": "2018-08-220T02:13:20"
}
}
],
"Service": [
{
"attribute": {
"name": "Resilience",
"value": "Terminated"
}
},
{
"attribute": {
"name": "Number",
"value": "1234"
}
},
{
"attribute": {
"name": "serviceStartDate",
"value": "2018-08-220T02:13:20"
}
}
]
}
]
}
}
]
}