function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sen19sen19 

write apex class from json

I want to create an apex class from below json. I am using json2apex but i am not able to get proper wrapper class from it. Can any one help me on this.
 My Json:
 { "id": "0Af2x000004Itv4", "validatedDeployRequestId": null, "deployOptions": null, "deployResult": { "id": "0Af2x000004Itv4CAC", "messages": null, "retrieveResult": null, "success": false, "checkOnly": true, "ignoreWarnings": false, "rollbackOnError": true, "status": "Failed", "numberComponentsDeployed": 1, "numberComponentsTotal": 2, "numberComponentErrors": 1, "numberTestsCompleted": 0, "numberTestsTotal": 0, "numberTestErrors": 0, "details": { "componentFailures": [ { "componentType": "AssignmentRule", "fileName": "sdx_sourceDeploy_1590739049091/assignmentRules/Case.assignmentRules", "fullName": "Case.Standard", "id": null, "problem": "In field: AssignedTo - no User named muralikrishna_r@hcl.om found", "success": false, "warning": false, "created": false, "changed": false, "deleted": false, "lineNumber": 4, "columnNumber": 21, "requiresProductionTestRun": false, "createdDate": "2020-05-29T07:57:36.000+0000", "knownPackagingProblem": false, "forPackageManifestFile": false, "problemType": "Error" } ], "componentSuccesses": [ { "componentType": "", "fileName": "sdx_sourceDeploy_1590739049091/package.xml", "fullName": "package.xml", "id": null, "problem": null, "success": true, "warning": false, "created": false, "changed": true, "deleted": false, "lineNumber": null, "columnNumber": null, "requiresProductionTestRun": false, "createdDate": "2020-05-29T07:57:36.000+0000", "knownPackagingProblem": false, "forPackageManifestFile": true, "problemType": null }, { "componentType": "AssignmentRules", "fileName": "sdx_sourceDeploy_1590739049091/assignmentRules/Case.assignmentRules", "fullName": "Case", "id": null, "problem": null, "success": true, "warning": false, "created": false, "changed": true, "deleted": false, "lineNumber": null, "columnNumber": null, "requiresProductionTestRun": false, "createdDate": "2020-05-29T07:57:36.000+0000", "knownPackagingProblem": false, "forPackageManifestFile": false, "problemType": null } ], "retrieveResult": null, "allComponentMessages": [ { "componentType": "AssignmentRule", "fileName": "sdx_sourceDeploy_1590739049091/assignmentRules/Case.assignmentRules", "fullName": "Case.Standard", "id": null, "problem": "In field: AssignedTo - no User named muralikrishna_r@hcl.om found", "success": false, "warning": false, "created": false, "changed": false, "deleted": false, "lineNumber": 4, "columnNumber": 21, "requiresProductionTestRun": false, "createdDate": "2020-05-29T07:57:36.000+0000", "knownPackagingProblem": false, "forPackageManifestFile": false, "problemType": "Error" }, { "componentType": "", "fileName": "sdx_sourceDeploy_1590739049091/package.xml", "fullName": "package.xml", "id": null, "problem": null, "success": true, "warning": false, "created": false, "changed": true, "deleted": false, "lineNumber": null, "columnNumber": null, "requiresProductionTestRun": false, "createdDate": "2020-05-29T07:57:36.000+0000", "knownPackagingProblem": false, "forPackageManifestFile": true, "problemType": null }, { "componentType": "AssignmentRules", "fileName": "sdx_sourceDeploy_1590739049091/assignmentRules/Case.assignmentRules", "fullName": "Case", "id": null, "problem": null, "success": true, "warning": false, "created": false, "changed": true, "deleted": false, "lineNumber": null, "columnNumber": null, "requiresProductionTestRun": false, "createdDate": "2020-05-29T07:57:36.000+0000", "knownPackagingProblem": false, "forPackageManifestFile": false, "problemType": null } ], "runTestResult": { "successes": [], "failures": [], "totalTime": 0, "apexLogId": null, "flowCoverage": [], "codeCoverage": [], "numFailures": 0, "codeCoverageWarnings": [], "flowCoverageWarnings": [], "numTestsRun": 0 } }, "createdDate": "2020-05-29T07:57:29.000+0000", "startDate": "2020-05-29T07:57:29.000+0000", "lastModifiedDate": "2020-05-29T07:57:37.000+0000", "completedDate": "2020-05-29T07:57:37.000+0000", "errorStatusCode": null, "errorMessage": null, "stateDetail": null, "createdBy": "0052x000001h6yF", "createdByName": "M Krishna", "canceledBy": null, "canceledByName": null, "runTestsEnabled": false, "runTestResult": null, "done": true } }

Wrapper class generated by jsonapex:

public class GitDeployHistroryWrapper {
public class Details { public List<ComponentFailures> componentFailures; public List<ComponentSuccesses> componentSuccesses; public String retrieveResult; public List<ComponentFailures> allComponentMessages; public RunTestResult runTestResult; } public String id; public String validatedDeployRequestId; public String deployOptions; public DeployResult deployResult; public class DeployResult { public String id; public String messages; public String retrieveResult; public Boolean success; public Boolean checkOnly; public Boolean ignoreWarnings; public Boolean rollbackOnError; public String status; public Integer numberComponentsDeployed; public Integer numberComponentsTotal; public Integer numberComponentErrors; public Integer numberTestsCompleted; public Integer numberTestsTotal; public Integer numberTestErrors; public Details details; public String createdDate; public String startDate; public String lastModifiedDate; public String completedDate; public String errorStatusCode; public String errorMessage; public String stateDetail; public String createdBy; public String createdByName; public String canceledBy; public String canceledByName; public Boolean done; public String runTestResult; public Boolean runTestsEnabled; } public class Successes { } public class RunTestResult { public List<Successes> successes; public List<Successes> failures; public Double totalTime; public String apexLogId; public Integer numTestsRun; public List<Successes> flowCoverage; public List<Successes> codeCoverage; public Integer numFailures; public List<Successes> codeCoverageWarnings; public List<Successes> flowCoverageWarnings; } public class ComponentFailures { public String componentType; public String fileName; public String fullName; public String id; public String problem; public Boolean success; public Boolean warning; public Boolean created; public Boolean changed; public Boolean deleted; public Integer lineNumber; public Integer columnNumber; public Boolean requiresProductionTestRun; public String createdDate; public Boolean knownPackagingProblem; public Boolean forPackageManifestFile; public String problemType; } public class ComponentSuccesses{ } public static GitDeployHistroryWrapper parse(String json) { return (GitDeployHistroryWrapper) System.JSON.deserialize(json, GitDeployHistroryWrapper.class); }
}

I am not getting proper output by using below: GitDeployHistroryWrapper callList= (GitDeployHistroryWrapper)JSON.deserialize(res.getBody(), GitDeployHistroryWrapper.class);
callList variable contains only below:
 callList-----GitDeployHistroryWrapper:[deployOptions=null, deployResult=null, id=https://login.salesforce.com/id/00D2x000004ubeDEAQ/0052x000001h6kKAAQ, validatedDeployRequestId=null]

Please help on this issue
SwethaSwetha (Salesforce Developers) 
HI Ananga,

As already answered here (https://salesforce.stackexchange.com/questions/310841/unable-to-create-apex-class-from-json), to update each field to have the format:
@AuraEnabled public $Type$ $fieldName$ { get; set; }
Aura/Lightning only works with @AuraEnabled fields, and {get;set;} allows you to convert your JSON to Apex

Please mark this answer as best so that others facing the same issue will find this information useful and also to close the thread. Thank you