I have created the custom service while testing from postman I am getting below error.
"An exception occured when deserializing a parameters - Exception occurred when parsing and deserializing parameter 'record' - 'Parameter 'record' is not found within the request content body"
Used JSON File:
{
"ID": "D0001",
"EffectiveDate": "2022-06-10",
"IsTrue": "No",
''DueDate" :"2022-07-10"
}
My service class method:
public str getUpdate(MyImportContract contract) { try { ttsbegin; infolog.clear(); contract.parmType();
// My code
}
}
Solution:
In the above example, I am directly passing element values I am not giving the reference i.e the reason I .am getting the above error. To rectify this follow the below steps.
Step 1: Need to change the JSON file format.
Step 2: Need to change the logic in the service method.
Getting a single record:
For a single record, no need to change the logic just change the JSON format.
JSON:
{
"record" : {
"ID": "D0001",
"EffectiveDate": "2022-06-10",
"IsTrue": "No",
''DueDate" :"2022-07-10"
}
}
// record is a contract class buffer in the service method parameter.
public str getUpdate(MyImportContract record)
Getting multiple records(list of records):
For this need to change the JSON file format and need to change logic. Need to use the list as a parameter for getting multiple records.
JSON:
{
"record": [
{
"ID": "140127-000003",
"EffectiveDate": "2022-06-05",
"IsTrue": "Yes",
"DueDate": "2022-06-05T13:49:51.141Z"
}
]
}
Logic:
[AifCollectionType('record', Types::Class, classStr(MyContract))] public str getLotUpdate(list record) { try { ttsbegin; ListEnumerator listEnum = record.getEnumerator(); while(listEnum.moveNext()) { infolog.clear(); contract = listEnum.current(); // Logic } } }
Keep Daxing!!
No comments:
Post a Comment