REST API / Problem parsing single element/attribute JSON Array Response

REST API / Problem parsing single element/attribute JSON Array Response

  

Platform Version 10+ and Personal Environment

Response header is -- [{"removed":{"$numberDouble":"0"}}]
This is the number of records deleted from an external database and does not vary with the exception of the number of records deleted.  --assuming the $numberDouble is Decimal--

The error is raised when the response is parsed and is described as follows in the modal.

An error was raised by the application:  
Failed to parse response of the method RESTNAME-METHOD of the RESTNAME API:
Parsing ":Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'METHOD Output Parameter' 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 deserialzied for a JSON array.  JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path ", line 1, position 1.

I have tried structures of simple attributes, structures of structures of simple attributes but I just cannot get past this error.  I am trying to avoid the overhead and complication that comes with Using the "OnAfterRequest" to modify the response.  I am using the same API with an Insert and Query and they work fine with their defined structure. I cannot alter the response received.  I have to be missing something simple...

Any ideas what the "JsonArrayAttribute" is meant to be or do.  I cannot find any reference to it anywhere... 

Hello Tony,

In terms of structure, this response is a list of objects (structure) that have an attribute called removed, that is of type structure that has an attribute of type text called $numberDouble.

But the $ at the start of the name... I don't think you can have an attribute in a structure whose name starts with the $ symbol... And your structure attributes names must match the json.

This is from the top of my head (on mobile), and I may be wrong, but I think if you remove the $ of the json and create the structure the way I put above, it should work.

Example: 

StructureA

    numberDouble (type text)

StructureB

    Removed (type StructureA)

So, I think you can't escape the OnAfterRequest here...

P.S. 

What the error you have is saying is that you are trying to deserialize a json that is an array to a simple structure, but you should deserialize to a list.

But I think the error is misleading, as the platform should consume correctly the rest given the output response.

And this makes me ask this... How did you consume this rest API?

It seems that you are creating the structure by hand. If so, you should use the automatic way, as the platform will create the correct structure for you.

See here: 

https://success.outsystems.com/Documentation/10/Extensibility_and_Integration/REST/Consume_REST_APIs/Consume_a_REST_API

Hello Tony

I attached an OML that does a "test".

I exposed a REST web service that gives you exactly the format you showed.
Than, I just consumed the web service in OutSystems, using the same method I sent in the link above.

OutSystems takes care of everything for you and everything is working.

Cheers,
Eduardo Jauch

"And your structure attributes names must match the json." - That's not true. By default the platform assigns the same name as the json to the attribute, but you can change it. There's a separate property fire the json name.

Hello kilian.

Yes. My mistake.

This test showed me this as the platform was able to create the structure with a valid name, different from the name in the json.

As the platform is able to consume the json and the error says specifically about the problem with the array, I wrongly assumed the error was with the name.

What let me think what is the code of the OP really like, as the platform takes care of the conversion of the json to a list...

Eduardo and Kilian, 

Thanks for the responses and information.  Like suggested I was able to use OS to build the response structure and make it work.  Moving forward, the responses from the Exposed API that I am consuming includes the "$name" on any non text field including integers and dates.  The results with the "$" come from Insert and Delete type queries.  Find queries don't have the "$" on the same fields.  So I am asking the developer responsible for that end of the API to check into the issue.  Those additional levels of JSON just to describe types other than string.