cancel
Showing results for 
Search instead for 
Did you mean: 

REST Adapter: Problem converting XML containing empty arrays to JSON

0 Kudos

Dear experts:

There are three scenarios when we want to convert the internal tables to arrays in JSON:

1) Contain more than one row in array; 2) Contain exactly one row in array; 3) Empty array.

Case 1 is correct default; and case 2 can be solved after apply note 2175218 and configure the rest adapter reference to Vadim Klimov's blog


In case 3, our expect result should be:


"ET_LIST": {

     "item": []

}

The default result will be:


"ET_LIST": ""

Of course we can use node functin "createIf" to create the node "item" in message mapping whether the internal table contain data, but the converted result will be:


"ET_LIST": {

     "item": [""]

}

I really don't know how to remove these quotes in []...

_LIST": {

     "item": []

}

"ET_LIST": {

     "item": []

}

Accepted Solutions (0)

Answers (1)

Answers (1)

apu_das2
Active Contributor
0 Kudos

Hi Zhang,

You can handle this using custom XML/JSON handling and null string tab in your receiver REST CC.

Can you please paste screen shot of your channel so that I can help you specifically.

Thanks,

Apu

0 Kudos

Sorry for my description is not clear.

I'm using REST sender adapter, and convert response message to JSON.

apu_das2
Active Contributor
0 Kudos

Please send screen shot of your sender CC Config ...

0 Kudos

The REST sender CC configured as below:

nisarkhan_n
Active Contributor
0 Kudos

Hi Chao

are you saying "" as apperaing in XML when rest converts below JSON to XML?

not very clear with your question

  1. "ET_LIST": { 
  2.      "item": [""] 

regards

Nisar

0 Kudos

Hi Nisar:   

     When the internal table in RFC return is empty, the part of XML will be as below:

     <ET_LIST>

          </item>

     <ET_LIST>

     Then the converted result will be:

     "ET_LIST": {

          "item": [""]

     }

    

     And our expected result should be:

     "ET_LIST": {

          "item": []

     }


     I don't know how to avoid "" appear.

nisarkhan_n
Active Contributor
0 Kudos

AS part of JSON standard "" represents the valid syntax for xml element which is appearing like

<value></value>  JSOn will be "value":[""]  (Assuming this is array object.

if you have xml tag as <value/> it should not show "" as tag itself is not appearing.

can you paste your right xml which you are getting because in xml which you have </item> is not valid.

0 Kudos

Dear Nisar:

I check the actual xml in rwb as below:

How can I make the mapping result becom <item/>?

nisarkhan_n
Active Contributor
0 Kudos

<item></item> has null value thats why you are getting "" in JSON,  in your cc configuration uncheck "treat null as string" and see if that works else then RFC should not send any value in item, not even blank then <item/> will appear.

bottom line for every element value in XML be it null or empty if element <item></item> occurs you will get "".

0 Kudos

Dear Nisar:

Actually the internal table "ET_LIST" in RFC is empty, and I create the node "item" in MM, otherwise the result will be: "ET_LIST": ""