I'm having trouble consuming an REST API that on the respose, has a attribute that can either be a structure, a integer or a text. Bellow there is an example of the structure returned on the API.
It is worth mentioning that when the
properties
data returns a text or a integer, it has no value to me, so I can ignore this. I'm only interested in the data of the structure.
Do you guys have any idea how I can consume or convert this structure to a JSON without having errors, basically I want to ignore the serialization erros. I've tried consuming the full response as a text and then serializing to JSON, tried consuming the
properties
structure as a text, and tried consuming it as an structure, but failed on all the atempts.
my oml is just a demonstration of how you could do it, you would of course have to adust it to your exact json structure. Can you share exact test data and your oml ?
Ok, can you go through it in debug, and share the result of GetStatement. And also share the proporties of the deserialise and also share the structure definitions you are deserialising to.
I can think of 2 reasons :
# you do a tiny thing different than me
# Deserialise on server is less tolerant than deserialese on client
As an example, I had a little try with regex_replace, see attached oml.
Mind you, this works on the one example JSON you have given, it should be tested on more examples, but it gives you an idea what I mean with 'preprocessing'.
Hi Dorine,
I tried your solution and got the following error:
"Failed to deserialize JSON to GetStatementResponse:
Error converting value 44516 to type 'ssContaCore.RestRecords.JSONSTPropertiesStructure'. Path '_embedded.transactions[0].properties', line 1, position 474."
my oml is just a demonstration of how you could do it, you would of course have to adust it to your exact json structure. Can you share exact test data and your oml ?
Dorine
I just changed to the structure that was supposed to be received, using the properties as the structure that I want. The error occured exactly in the properties attribute and it makes sense, because it tried to convert a text to a structure, it's like trying to convert a text to a boolean, it will result in an error.
Unfortunately I can't share the data and the oml.
Ok, can you go through it in debug, and share the result of GetStatement. And also share the proporties of the deserialise and also share the structure definitions you are deserialising to.
I can think of 2 reasons :
# you do a tiny thing different than me
# Deserialise on server is less tolerant than deserialese on client
I´ ll verify the second hypotheses
Dorine
Oke, I can confirm that deserializing on server doesn't work.
see attached oml for showcase.
So if this is reactive or mobile, you still have the escape of doing it on client side, for traditional, you're out of luck. You'll have to somehow preprocess the text with something like regexReplace and/or forge component 'JSON tool kit', taking out all the stuff with the unwanted values.
Dorine
PS : 2 final remarks, they won't help you, but I'd like to say them
1) i think an api that has different values / structures for the same item in it, is poor design
2) I think software that has same name/look/function in the eye of the developer, behaving differently dependent on where in the architecture/stack it is executed, is poor design
As an example, I had a little try with regex_replace, see attached oml.
Mind you, this works on the one example JSON you have given, it should be tested on more examples, but it gives you an idea what I mean with 'preprocessing'.
Dorine
Hi Tarek,
Did you check you JSON is in correct format?
After correcting your JSON you have create proper structure for that.
I hope this will help you
Regards,
Amreen