REST returns Boolean as XML not JSON

REST returns Boolean as XML not JSON

  
I have a REST API and want to return a single value e.g. one boolean  or one text. when i test the function in SoapUI it always comes back as XML not JSON. Same when i use a browser like chrome. If I create a structure with one Boolean and use that structure as the output then JSON is returned. Why do i have to use a structure when i want to just return one value? Is there a way to tell the REST service to always return JSON even for just one value?

Herer is what SoapUI shows me as the return from the REST call to the function that returns a boolean
<data contentType="text/plain; charset=utf-8" contentLength="4"><![CDATA[true]]></data>

attached is a sample espace

Thank you for any tips.
Hello Fabian,

you have to set your output to a structure of type Boolean to obtain the desired result.

Something like {"value": true}






Hi Joao

Thank you for your reply.

I stated that as well that i have to use a structure. My question is why is a single value returned as XML and not JSON inside a REST API? or why do i have to use a structure when i want to return a single value?
Actually I believe the output is not XML like you say in your original post.

I think that's Soap UI processing the output in XML format.

In the response window you have several "side tabs" with XML, JSON, RAW, etc formats.
The raw data is actually just plain text saying "true".
I see so it's not XML. However it's not JSON which i expect.

When i click on the JSON tab in Soap UI it is telling me "The content you are trying to view cannot be viewed as JSON"

the question remains why is an outSystems REST API not returning JSON. It's not a problem since there is a workaround by using a structure but i'm just wondering if this is by design or a bug.

I should maybe submit this to support.

Well, can't give you a certain answer. Did some search on the documentation (which by the way is fairly good) and found something I believe also applies to responses.

http://www.outsystems.com/help/servicestudio/9.0/Integrating_with_other_systems/Web_Services/Supported_Media_Types_in_REST_API_Requests.htm

From what it says here Records/List result in JSON, Basic types result in text and binary is anything.

This is why the first time you got text and after changing to a structure you got JSON.
in SoapUI when i click on the JSON tab it says "The content you are trying to view cannot be viewed as JSON"

I submitted a support call. I'll let you know what they say.
This is what OS Support had to say

=======================================
The type mappings for REST API outputs are done like you mention by design.

This allows for greater flexibility when defining our customer's REST APIs. If the customer wants a custom format they can simply add a text output and built it themselves, for example. Some APIs are also simpler if you just return the number or boolean instead of forcing the consumers to parse a JSON object to obtain a single value.

It's currently not possible to change the way this works.

Please let us know if you have further questions regarding this matter.

Best regards,
Ricardo Silva
============================================================
Hi Fabian,

Just out of curiosity, if the output of a basic type was json (instead of the plain text) what was the name of the attribute that you were expecting?

But yes, like Ricardo answered you if the basic types also returned json it would make impossible to have non-json services. 
Like this, you can even have a method that returns XML (using a output of type Text and writing the xml string yourself). Even though the Platform itself never generates XML.

Regards,
João Rosado

i was expecting it to be the name of the Output Parameter of the action.
e.g output parameter name is IsValid so i was expecting this {"IsValid":"True"}