Send Json Request Using tRestClient With Nested Object in talend

4.4k views Asked by At

Thanxx in advance for your help :)
I am trying to use tRestClient to send request with json to add product in my webservice which contain json Array for attribute inventory
ex :

{
"handle": "iPad2",
"inventory": [
    {
        "outlet_name": "one",
        "count": "100"
    },
    {
        "outlet_name": "two",
        "count": "200"
    }
]
 }

I have data in single row in which one handle can have multiple outlet and count so i have create my job like this

here tIdempiereInput is my custom component which will act like tPostgresInput tIdempiereInput -> tXmlMap -> tRestClient

 component i have used tRestClient to

Map handle ,outlet and count using tXmlMap sot it will convert my row date in document which will be used by tRestClient outlet

My Job Works Fine But my problem is, it send request for each handle without grouping them in single object like this
Request 1)

{
"handle": "iPad2",
"inventory": [
    {
        "outlet_name": "one",
        "count": "100"
    }
]
}  

Request 2)

{
"handle": "iPad2",
"inventory": [
    {
        "outlet_name": "two",
        "count": "200"
    }
  ]
 }

So it makes diffrent request for each record rather then grouping outlet and count with handle and make single request for it!!

I know about tAdvancedFileOutputXML using it we can generate XML with nested sturcuture using grouping element and loop but don't know how to do same thing with tXmlMap and tRESTClient..

1

There are 1 answers

1
akb On

Did you see the option "All in One" on the tXMLMap output? When you are in mapping mode, click on the wrench icon of your output and make sure "All in One" is set to true - this seems to do the trick to put all the looping elements into one output row.