web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

JSON List API payload request value deserialize using X++

(2) ShareShare
ReportReport
Posted on by 188
Hi experts,
 
I have developed an API and I am expecting to get request value from external application in the following format:
 
{
  "_leaveDetails": [
    {
      "personnelNumber": "PN001",
      "leaveType": "SICK"
    },
    {
      "personnelNumber": "PN002",
      "leaveType": "SICK"
    }
  ]
}
 
Not sure where I am wrong, my service class nothing reading from the JSON payload. always this bringing the null value.
Need your guidance to fix this issue.
 
I am thinking either JSON payload structure is wrong or List contract class signature is wrong or service class parameter is wrong.
 
List class signature:
[DataMemberAttribute('_leaveDetails'), DataCollectionAttribute(Types::Class,
classStr(XXXChildRequest))]
public List parmLeaveDetailList(List _leaveDetailList = _leaveDetails)
 
Service class signature
public str processAbsenceRequest(XXXParentListRequest _leaveDetails) // List class
 
 
I wrote following code but getting error while accessing from service class:
 
Request class:
 
[DataContractAttribute]
public class XXXChildRequest
{
    str   leaveType;
    str         personnelNumber;
    List        leaveDetailList;

    [
        DataMemberAttribute('Leave Type')
        //SysOperationDisplayOrderAttribute('1'),
        //SysOperationLabelAttribute(literalStr('Leave Type'))
    ]
    public TransDate parmLeaveType(Str _leaveType = leaveType)
    {
        leaveType = __leaveType;

        return leaveType;
    }

    

    [
        DataMemberAttribute('Personnel Number')
        SysOperationDisplayOrderAttribute('2'),
        SysOperationLabelAttribute(literalStr('Personnel Number'))
    ]
    public str parmPersonnelNumber(str _personnelNumber = personnelNumber)
    {
        personnelNumber = _personnelNumber;

        return personnelNumber;
    }

    
}
 
List Contract class:
 
[DataContractAttribute]
public class XXXParentListRequest
{

List _leaveDetails;

public void new()
{
_leaveDetails = new List(Types::Class);
}

[DataMemberAttribute('_leaveDetails'), DataCollectionAttribute(Types::Class,
classStr(XXXChildRequest))]
public List parmLeaveDetailList(List _leaveDetailList = _leaveDetails)
{
_leaveDetails = _leaveDetailList;
return _leaveDetails;
}
}

Service class:
 
[SysEntryPointAttribute]
public class XXXRequestService
{
    public str processAbsenceRequest(XXXParentListRequest _leaveDetails) // List class
    {

        List leaveList;
        ListEnumerator listEnum;

       // Code to get list request value

   
        }
        return jsonString;
    }

}
I have the same question (0)
  • Martin Dráb Profile Picture
    239,632 Most Valuable Professional on at
    Are you saying that processAbsenceRequest() gets called (i.e. F&O does accept the message) but _leaveDetails parameter is null?
  • Vinay S Profile Picture
    188 on at
    Thanks Martin for your reply.
     
    I have following JSON payload in postman and this gives following error
    JSON
    {
      "_leaveDetails": [
        {
          "personnelNumber": "PN001",
          "leaveType": "SICK"
        },
        {
          "personnelNumber": "PN002",
          "leaveType": "SICK"
        }
      ]
    }
     
    Postman error:
     
    As per my understanding, the following line of code might be the issue and looking your expert advise on this.
     
    List Contract class:
     
    [DataContractAttribute]
    public class XXXParentListRequest
    {

    List _leaveDetails;

    [DataMemberAttribute('_leaveDetails'), DataCollectionAttribute(Types::Class,
    classStr(XXXChildRequest))]
    public List parmLeaveDetailList(List _leaveDetailList = _leaveDetails)
    {
    _leaveDetails = _leaveDetailList;
    return _leaveDetails;
    }
    }
     
    Service class:
     
    [SysEntryPointAttribute]
    public class XXXRequestService
    {
        public str processAbsenceRequest(XXXParentListRequest _leaveDetails) // List class
        {
    
            List leaveList;
            ListEnumerator listEnum;
    
           // Code to get list request value
    
       
            }
            return jsonString;
        }
    
    }
     
  • Martin Dráb Profile Picture
    239,632 Most Valuable Professional on at
    Okay, this is very different information than the original description ("always this bringing the null value").
     
    I see that the names of your data members don't match the properties in JSON. For example, you have personnelNumber in JSON but DataMemberAttribute('Personnel Number') in X++. Change it to DataMemberAttribute('personnelNumber'). Similarly with _leaveType.
  • Vinay S Profile Picture
    188 on at
    Thanks Martin.
     
    I tried that way also and now here is the modified code but still facing the same error:
     
    My worried here is my approach is correct or I am missing something either on JSON request body or XXXParentListRequest class or in service class parameter? because from the postman error that's seems 
    issue with List class or list related payload structure.
     
    List Contract class:
     
    [DataContractAttribute]
    public class XXXParentListRequest
    {

        List _leaveDetails;

       [DataMemberAttribute('_leaveDetails'), DataCollectionAttribute(Types::Class,
       classStr(XXXChildRequest))]
       public List parmLeaveDetailList(List leaveDetails = _leaveDetails)
      {
          _leaveDetails = leaveDetails;
           return _leaveDetails;
      }
    }
     
    Service class:
     
    [SysEntryPointAttribute]
    public class XXXRequestService
    {
        public str processAbsenceRequest(XXXParentListRequest _leaveDetails) // List class
        {
    
            List leaveList;
            ListEnumerator listEnum;
    
           // Code to get list request value
    
       
            }
            return jsonString;
        }
    
    }
     
    [DataContractAttribute]
    public class XXXChildRequest
    {
    
        str         personnelNumber;
      
    
        
        [
            DataMemberAttribute('personnelNumber')
            
        ]
        public str parmPersonnelNumber(str _personnelNumber = personnelNumber)
        {
            personnelNumber = _personnelNumber;
    
            return personnelNumber;
        }
    
        
    }
     
    JSON
    {
      "_leaveDetails": [
        {
          "personnelNumber": "PN001"
        },
        {
          "personnelNumber": "PN002"
        }
      ]
    }
     
  • Martin Dráb Profile Picture
    239,632 Most Valuable Professional on at
    I think you should be using AifCollectionTypeAttribute instead of DataCollectionAttribute? You can keep DataCollectionAttribute in place and add AifCollectionTypeAttribute for the parameter and the return value.
     
    By the way, you can also check the structure of the JSON by removing XXXParentListRequest from the parameter and return it from the service instead.
  • Suggested answer
    Waed Ayyad Profile Picture
    9,135 Super User 2026 Season 1 on at
    Hi,
     
    Did you change  XXXChildRequest  contract parameters to be the same as JSON? I mean DataMemberAttribute('') ?
     
     
     

    Thanks,

    Waed Ayyad

    If this helped, please mark it as "Verified" for others facing the same issue

     
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 804

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 639 Super User 2026 Season 1

#3
Subra Profile Picture

Subra 528

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans