I'm running into a problem with my JSON2Apex code where I'm unable to define objects of another class in the current class I'm working on and I'm not sure where I'm running afoul. I tried changing the 'public class' to a 'global with sharing class ... extends ...' as referenced here, but I'm now getting the below error message:
Line: 1, Column: 27 Dependent class is invalid and needs recompilation: Class restCallout : Non-virtual and non-abstract type cannot be extended: JSON2Apex
I'm not sure how to tie one class (ie make one an ancestor class) into another so I can perform the following call:
JSON2Apex data = (JSON2Apex)JSON.deserialize(res.getBody(), JSON2Apex.class);
I've also tried making my JSON2Apex class a 'public virtual class' so I can 'extend' my "restCallout" class, however that yields a different error message as well:
Line: x, Column: 1 System.JSONException: Expected JSON2Apex.Value but found [line: x, column: x]
Class 1:
public class restCallout extends JSON2Apex{
public static void restGroups() {
HTTPRequest req = new HttpRequest();
req.setMethod('GET');
req.setHeader('Accept', 'application/json');
req.setEndpoint('callout:rest_endpoint1/');
HTTPResponse res = new Http().send(req);
JSON2Apex data = (JSON2Apex)JSON.deserialize(res.getBody(), JSON2Apex.class);
}
...
}
Class 2:
public virtual class JSON2Apex {
public class...{
}
}