I have multiple-layer predefined classes that JSON.deserialze() can successfully map the JSON data into.
The challenge is in processing the deserialized data. In each layer I need to use if
to check whether the class instance is null
and the property is null
before proceeding.
Is there a better way?
function code:
public void function1(){
// better way to handle the null check in all these functions?
if(issueResponse.issues != null && issueResponse.issues[0].id != null)
// proceed;
}
Class code:
public class IssueResponse {
public String startAt;
public String total;
public List<Issue> issues;
}
public class Issue {
public String id;
public String key;
public Fields fields;
}
public class Fields {
public String summary;
public IssueType issueType;
public Assignee assignee;
public List<FixVersion> fixVersions;
}
public class IssueType {
public String name;
}
public class Assignee {
public String emailAddress;
}
public class FixVersion {
public String name;
}