Hello everybody,
I'm having several issues like this and I'm having trouble understanding JSON serialization/deserialization. I would like to try to understand what is happening and what are the best practices to reach a solution to this problem.
The solution seemed simple considering that OutSystems itself guides me to change the deserialized type to be a normal .NET type (What would that be?) or add JsonObjectAttribute (What would that be?) to the type to force it to deserialize from a JSON object.
I tried to change the data type of the structure, but I have only the List type available and List is just the model that is not recommended by OutSytems.
I haven't modeled the database to receive this TELEFONE field yet. I believe that I will only store the first record, being unnecessary to bring a TELEFONE object containing an array of TELEFONES.
Attached is an OML file with a simple flow of the request. could guide me in solving this problem.
Thank you very much to everyone in the community who has contributed to my studies.
Hi bruno,
It seems problem with the API Json response. Telefone Attribute in the response body is as list type but when there is only one record , it is no more List.
Now check at Line number 282,
That's why outsystems unable to parse it in List item data type.
If in your project there is no use of List of telephone, you can ignore this attribute by deleting the Telephone attribute from your structure and It will work.
Note: Name of attribute doesn't impact. You can give name whatever you want. But Name in JSON property of structure must be same as the name of API json response attribute.
Cheers,
You nailed it Rahul, that would explain why I was getting an empty telephone list in my response for every object in the array.
Understand.
I'm going to study a logic to check what kind of structure I'll have to use.
Thank you very much @Rahul Kumar
Thank you @AJ. and @Bruno Menezes Noronha
Hi Bruno,
I think , Things are not correctly mapped during assignments.
You can make a similar data type of your local variable as APi response.
For example. Your api response data type is
GetAtualResponse , So your local variable data type should be same GetAutialResponse
or,
If you do not want to change data type of your local variable. then only take that list value from your response.
For example :
your local variable
SenadoresResponse data type ListaParlamentarEmExercicio , So during assignment take only
ListaParlamentarEmExercicio value from response.
Please check Oml.
Thanks
Hello @Bruno Menezes Noronha,
I have made the following changes in the attached oml to resolve the error you are encountering:
1. Moved the 2 entities shown below to ApiConsumer:
This change was merely done so I could compile and build the oml because the oml you provided was missing the RADAR_Data dependency.
2. Changed:
To:
3. Changed:
This is the important one, because having an attribute with the same name 'Telefone' as the Structure name was causing the error.
4. I added logic to display the 'Individuo' data in a table as shown below, because that is what you were attempting to save in the database. This is just to give you a visual confirmation of the fix.NOTE: With the current logic, each time you click the'Get API' button, the data will be irepeatedly nserted into the entity so you will get duplicates/multiple entries in the 'Individuo' entity.
Hope this helps,
Regards,
AJ
Once again thank you very much @AJ.
In other routines I make the deal not to duplicate the records and if there is an update in the api data I update the necessary information.