Failed to parse response of the method
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'ssTestingTool2_IS.CcParserName+RESTAlternative_country2' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.Hi, Good day! I am encountering this error on my API,
Attached is my sample response.
How should I fix this?edit: Is it possible that the cause of this is because the alternative_country structure has sometimes "alternative_countries": { US,GB,JP} and on the other data it is like this "alternative_countries":[] ?
Hi,
The issue is with the alternative_countries object, Because the keys are dynamic you can't parse this to a structure or you have to create every possible country in the structure enable to parse it.
If you don;t need this field you could remove it from the sample response to generate the api, this way OutSystems skipped this field in serilization
In addition to my response,
The JSON is 100% valid, only native OutSystems can't handle this response, because of the dynamic json keys in alternative_countries,
I'm pretty sure that
{ US, GB, JP }
Isn't valid JSON? For one, there's missing quotes.
{ US, GB, JP } is indeed not valid, But I can't find this in the provided JSON file, So my guess was this was type to explain the difference between a object and an array.
But the provided JSON files is 100% correct
Ah, right, missed the attachment. Thx.
Hi @Damian Fonville ,
Tried to remove the field and it worked! Thanks
Hello Dianara,
It seems response of API is not matching your output structure of this API.
Try to test API first on service studio and copy output to output body. Also you can check service center => monitoring => integration and find error of that API.
You may also need to increase logging level of that API to get request and response then compare it to your output structure by following steps into URL: https://success.outsystems.com/documentation/11/extensibility_and_integration/set_the_logging_level_of_rest_and_soap_integrations/
I have done this Test the API first then copy the output to the response body, but still, I am getting the error
I would recommend to set logging level of that API to full as mentioned into URL I share with you then call your API one more time then go to service center => monitoring => integration and find the error of API open details and download response Json and compare it to Json returned when you test API using service studio, you may find any difference that causing issue.
Hi @Dianara Bathan ,
Try to debug OnAfterEvent of API and check response there.
Best,
Arun
Hi Dianara Bathan ,
The JSON string which you are passing to deserializing is of list type but the structure which you have assigned to deserialize action is not list type. Kindly make it of list type and then try.
Hope this helps you.
Hi Dianara,
"Is it possible that the cause of this is because the alternative_country structure has sometimes "alternative_countries": { US,GB,JP} and on the other data it is like this "alternative_countries":[] ?"
"{US,GB,JP}" isn't valid JSON, so if that's what is returned, it rightly fails. For one, you cannot have a list of things in an object, and secondly, if it were an array, then you'd need quotes around the values, like this:
[ "US", "GB", "JP" ]
So perhaps you can check what's the actual JSON in both cases, so we can advise you what to do.
Note that the error you get does, in general, mean that an attribute is sent polymorphic, for example, it is normally sent as above (an array), but if there's no data it's sent like {}, for example.
Ok, I missed the attachment. There's two problems here. For one, these kinds of dynamic keys can't be handled by OutSystems:
"alternative_countries": { "US": 61, "GB": 13, "CA": 8 }
OutSystems wants attributes to be fixed.
Secondly, there's a problem with "alternative_countries" being polymorphic: sometimes it's an object as above, sometimes an array:
"alternative_countries": []
There's a number of possibilities to fix this. You can either use the On After Response and fix the JSON into something that OutSystems understands, or you just get the JSON in its entirety and use ArdoJSON to parse it (especially JSON_Objectify for the dynamic attributes).
Since this comes up a lot on the forum, I created an Idea for it. Vote for it here.
As a reply to my Idea, Leonardo Fernandes replied with an example how to handle your case with his AdvancedREST Forge asset.