Quantcast
Viewing all articles
Browse latest Browse all 1306

REST Adapter: Problem converting XML containing arrays to JSON

Hi all,

 

we are using REST as a Sender Adapter. Works (almost Image may be NSFW.
Clik here to view.
) like a charm

 

The problem we are facing is that we have an Array-like Element in the Repsonse XML DataType. Depending on the amount of actual elements in the array, the element gets converted to a JSON Array or JSON OBject.

 

E.g. If the element contains exactly 1 item, it is converted to a JSON object. If it contains more than one item, it is comverted to an array. if it contains no elements, it is not contained in JSON at all.

 

Case 1: More than one element in XML

 

consider following response XML:

<resultlist>  <item><value>item 1</value></item>  <item><value>item 2</value></item>  <item><value>item 3</value></item></resultlist>

it gets correctly converted to

{    "result": {        "item": [            {  "vlaue": "item 1"  },            {  "vlaue": "item 2"  },            {  "vlaue": "item 3"  }        ]    }
}

 

Case 2: Single element in XML

 

consider following response XML:

<resultlist>  <item><value>item 1</value></item></resultlist>

it gets NOT correctly converted to

{    "result": {        "item":            {  "vlaue": "item 1"  }    }
}

expected result:

{    "result": {        "item": [            {  "vlaue": "item 1"  }        ]    }
}

Case 3: No elements in XML

 

consider following response XML:

<resultlist/>


it gets NOT correctly converted to

{    "result": ""
}

 

expected result:

{    "result": {        "item": []    }
}

Bottomline

 

The point is that the consumer of the result cannot rely on the structure of the content. Sometimes the element is just en element, sometimes it is an array, sometimes it isn't even there...

 

 

 

The issue has been addressed at the following locations, but I havent found a solution and/or a note yet...

 

 

 

Thanks and best regards,

Sergei


Viewing all articles
Browse latest Browse all 1306

Trending Articles