cancel
Showing results for 
Search instead for 
Did you mean: 

REST Adapter: json array to xml in receiver adapter

stefan_bosshard2
Explorer
0 Kudos
2,096

Hi all,

I wonder if it is possible to convert following json response into xml within standard REST receiver adapter?

{

"query": {

  "resultCode": 0,

  "columns": ["id", "customer_no", "language"],

  "table": [

   ["331106", "3001158", "DE"],

   ["322205", "11407729", "DE"],

   ["313331", "346559", "DE"] 

  ]

}

}

For example in something like this:

<table>

<column>

<id></id>

<customer_no></customer_no>

<language></language>

</column>

<column>

<id></id>

<customer_no></customer_no>

<language></language>

</column>

</table>

I configured my rest adapter as following:

How must the message type look like so that I could use the response for a proper mapping?

Thanks for any idea.

Stefan

View Entire Topic
maheswarareddykonda
Active Contributor
0 Kudos

Hi Stefan,

yes, its possible to convert that json to xml when your PI system is grater than 7.4SP10 patch level 5

below is the structure you can create.

<?xml version="1.0" encoding="UTF-8"?>

<ns0:RestResponseData xmlns:ns0="http://chsefel.com/TRAINING_PI/REST">

   <query>

      <columns>

         <node1>id</node1> (0..unbounded)

        

      </columns>

      <resultCode>0</resultCode>

      <table>

         <record>(0..unbounded)

            <node2>331106</element>(0..unbounded)

         </record>

        

      </table>

   </query>

</ns0:MT_RES>

and your configuration seems good for response side which is below to your screenshot.

and request side you have kept data formate is JSON, here can confirm one thing ,

are you sending json data to receiver system. if yes i think you need to do small correction in request side like. check for convert xml Payload to json also

Thanks,

Maheswarareddy

stefan_bosshard2
Explorer
0 Kudos

Hi Maheswarareddy,

thanks for your answer. Well we have 7.31 SP16 .... but anyway I tried it out but it was not working.

I used this xsd for my test:

But it still does not convert it into wished structure.....

Do you see any mistake?

Thanks and regards

Stefan

maheswarareddykonda
Active Contributor
0 Kudos

Hi Stefan,

>>But it still does not convert it into wished structure.....

this mean you are getting mapping exception due to structure mismatch, if so you can create structure as per that response structure.

can you please tell me which method(POST,PUT,GET) you are using?

if you are using GET method..i will suggest you follow way to run interface

1. create an receiver communication channel

2.while you create communication channel you need to give url, in that url in case you need to keep variables, keep as hardcoded like below

url : https://xxxxxxxxxxxxxx/waste-transfers/43b3215e-4f85-41fd-9204-a4c100b14c02

actually url we suppose to keep in real time like https://xxxxxxxxxxxxxx/waste-transfers/{ID}

that id we need to pass dynamically.

so i suggest try to hard code varables first in url

3.create an dummy ico, i mean with out sender and receiver structure.

4.and run that interface

once you run that interface you must be see successfully msg in xml formate(because that receiver cc will convert json to xml)

5.as per that response converted xml data , you create structure.

if you still have doubts, please let me know full requirement and what error you are getting.

regards,

Maheswarareddy

stefan_bosshard2
Explorer
0 Kudos

Hi Maheswarareddy,

well I do not get a mapping exception but I do not get my wished structure.....

The request works perfect and is with static url.

I got the response xml in this format:

Does not matter what kind of response interface I created before......

Any idea?

Regards

Stefan

maheswarareddykonda
Active Contributor
0 Kudos

Hi Stefan,


in mean time i also checked that how Rest adapter is converting structure.


yes REST adapter not converting as we expecting when specially nested structure case,


and its not an matter ,  you will get data in flat structure, accordingly you can follow the structure.


like if field comes multiple times mention as 0..unbounded.


however your screenshot seems wsdl structure .i dont think that data you are getting from PI server and must have tested in soap ui.


in case you really get that data with that structure, i believe you can not handle by graphical mapping...need to go for either xslt or java mapping because that structure has extra namespaces.

Thanks & Regards,

Maheswarareddy



stefan_bosshard2
Explorer
0 Kudos

Hi Maheswarareddy,

thats correct - I tested with SOAP UI as a consumer and got above response, which was so converted in SAP PI from json to xml....

So then I will try to manage it with XSLT Mapping....mapping from reallly flat to what I would excpect

Thanks anyway!!!

Regards

Stefan

0 Kudos

Hi Mahesh, I have similar requirement to convert the JSON response to XML with below structure having tables, columns and rows. Bit complicated JSON structure. Will it be possible to convert it into XML structure having the coloumn and rows values correspondingly using the standard receiver adapter.

{"outputs":

{"Result_Code":null,

"Result_Error":null,

"Result_Message":null},

"tables":[

{"columns":

["Workcenter_Code","Part_No","Job_No","Operation_Code","Log_Date","Workcenter_Status","Duration","Op_No","Update_Date","Shift"],

"rows":[

["S_A114M1","6026581","7603942","Laserschweißen (laserweld)","2023-07-01T05:00:00Z","09 Aus (Off)",8.00000,10,"2023-08-30T09:57:00Z","3rd"],

["S_A114M1","6026581","7603942","Laserschweißen (laserweld)","2023-07-03T13:00:00Z","09 Aus (Off)",8.00000,10,"2023-08-30T09:57:00Z","2nd"],],

"rowLimitExceeded":false}],

"transactionNo":"258654"

}