Consumed webservice returns all data in data

0
Hi, I am consuming webservices (http://developer.axosoft.com) and all responses are in "data". Two small examples: {"data": { "start_date": "2013-05-29T22:00:00Z", "build_number": "", "id": 30, "item_type": "features", "assigned_to": { "type": "user", "id": 119, ... and {"data": [ { "id": 1, "first_name": "Administrator", "last_name": "", "full_name": "Administrator", "email": "", ... As you can see in the two JSON strings both responses use "data" but the first is a single object and the second is a list. How do I model this in Mendix? I have tried a single association "data" and multiple association "_data" but that does not help because the module does not know which to pick and the result is not predictable. Do you have a suggestion how to handle this? Can I call the webservice but without the automatic deserialization? Regards, Paul
asked
2 answers
1

I fixed it and this is how I did it:

In the Java action getWithParams put empty in targetObject; this prevents automatic deserialization. Attribute RequestBody of the returned RequestResult object contains the JSON. Replace the text as you like (data to datasingle in my case) and call the deserializeJsonToObject Java action.

answered
0

Hi Paul,

The proper solution to this is to create a transient wrapper entity that has no attribute, but instead a reference (or referenceset if the contents is an array) named 'data' that leads to the real object you need to fill. Then pass in an new instance of this wrapper object to the rest call.

In the case of colliding names for the references, you can prefix the name with additional underscores.

answered