Deserializing JSON different types in same attribute

Deserializing JSON different types in same attribute

  

Hi,

I'm trying to parse a JSON where the attribute assumes different data structures, if this attribute is null we receive a structure, if not we receive another.

For example: CountryID in some rows assumes that structure (when null):

And in the cases that returns a value comes like this:


The automatic structure generated by the platform assumed that the structure of CountryID is:


but for the cases when the field comes filled in, this exception occurs:

 Parsing 'AuthenticateResponse.user.ClientUser.ClientUser[2].Client.CountryID': Error converting value "185" to type 'ssPortalServicosTICore.CcSmartCloudServices+RESTAuthorizationUserProfileList'. Path 'AuthenticateResponse.user.ClientUser.ClientUser[2].Client.CountryID', line 1, position 3841.


Any ideia?

(using Service Studio 10.0.721.0)


Kind Regards,

Mónica

Solution

Hello Mônica.

OutSystems can't handle this automatically.
Use the On After Response REST event to change the JSON response in order to make it a structure if it receives a value. This way you stop getting the error and always know how to use the data without extra logic.

Cheers

Solution

Eduardo Jauch wrote:

Hello Mônica.

OutSystems can't handle this automatically.
Use the On After Response REST event to change the JSON response in order to make it a structure if it receives a value. This way you stop getting the error and always know how to use the data without extra logic.

Cheers

Thanks Eduardo!


I changed the JSON, and fixed the problem.


Cheers!