I have the following piece of code.

global with sharing class OpportunityUpdate {
global static void updateOpportunity() { 

    RestRequest req = RestContext.request;
    RestResponse res = RestContext.response;

    Blob body = req.requestBody;
    String requestString = body.toString();
    AreaRequestWrapper areaRequestRecord = parse(requestString);

public class RequestWrapper{
public String SourceSystem; 
public Integer MessageVersion;  
public cls_messages messages;
class cls_messages {
    public cls_Transaction[] Transactions;
class cls_Transaction {
    public cls_MetaData MetaData;
    public String OId;  
    public String TId;  
    public boolean IsTransactionComplete;
    public String PId;  
class cls_MetaData {
    public String Guid; 
    public String MessageOperation; 
    public String Country;  
public static RequestWrapper parse(String json){
    return (RequestWrapper) System.JSON.deserialize(json,RequestWrapper.class);

I have generated above AccountWrapper using JSON2Apex from the following JSON


My problem here is that, when I parse using parse(String) method, it is giving null for the inner class values. The above System.debug prints the following

[MessageVersion=1, SourceSystem=Area, messages=cls_messages:[Transactions=null]]

I am not sure why Transactions is coming as null.

I went through the below link as well. But in my case I do not have nested inner classes.

Getting null for inner classes in complex JSON deserialization


Your JSON doesn't match your data structure. In Apex, you have

public cls_Transaction[] Transactions;

in the plural, but your JSON has


in the singular.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.