Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XML to JSON in BPEL

RakeshKrNov 23 2016

Product Version - 12.2.1

Scenario:

SOAP service (sync) request and response

Refrence: REST / JSON service (Some cloud service)

In BPEL I am getting request and after doing transformation trying to call REST service with JSON payload.

Issue:

I get the request then based on the request I can build XML (Transform or Assign).

Example XML:

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

   <Root-Element xmlns="http://TargetNamespace.com/ServiceName">

      <messageRequest>

         <appId>w38748374283478273</appId>

         <global/>

         <messages>

            <message>

               <content>

                  <priorityService>true</priorityService>

                  <data>Test Message</data>

                  <mimeType>text/plain</mimeType>

               </content>

               <overrideMessageId>0</overrideMessageId>

               <startTimestamp>0</startTimestamp>

               <expiryTimestamp>0</expiryTimestamp>

               <subscribers>

                  <subscriber>

                     <ufid>abc@abc.com</ufid>

                  </subscriber>

               </subscribers>

               <type>PUSH</type>

            </message>

         </messages>

      </messageRequest>

   </Root-Element>

</VariableXML>

The Varibale VariableXML is based on a NXSD schema.

After populating the variable I can simply assign to a JSON object variable which automatically converts to this (Variable2 is JSON object):

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

   <json>{

   "Root-Element": {

      "messageRequest": [

         {

            "appId": [

               {

                  "$": "w38748374283478273"

               }

            ],

            "messages": [

               {

                  "message": [

                     {

                        "expiryTimestamp": [

                           {

                              "$": 0

                           }

                        ],

                        "subscribers": [

                           {

                              "subscriber": [

                                 {

                                    "ufid": [

                                       {

                                          "$": "abc@abc.com"

                                       }

                                    ]

                                 }

                              ]

                           }

                        ],

                        "overrideMessageId": [

                           {

                              "$": 0

                           }

                        ],

                        "type": [

                           {

                              "$": "PUSH"

                           }

                        ],

                        "content": [

                           {

                              "data": [

                                 {

                                    "$": "Test Message"

                                 }

                              ],

                              "priorityService": [

                                 {

                                    "$": true

                                 }

                              ],

                              "mimeType": [

                                 {

                                    "$": "text/plain"

                                 }

                              ]

                           }

                        ],

                        "startTimestamp": [

                           {

                              "$": 0

                           }

                        ]

                     }

                  ]

               }

            ],

            "global": [

               {

                  "$": null

               }

            ]

         }

      ]

   }

}</json>

</Variable2>

Notice the highlighted $ symbols. They are causing issue while calling the REST service. The JSON I am looking to produce is (without $ symbols):

{

    "messageRequest": {

        "appId": "w38748374283478273",

        "global": { },

        "messages": {

            "message": {

                "content": {

                    "priorityService": "true",

                    "data": "Test Message",

                    "mimeType": "text/plain"

                },

                "overrideMessageId": 0,

                "startTimestamp": "0",

                "expiryTimestamp": "0",

                "subscribers": {

                    "subscriber": [

                        {

                            "ufid": "abc@abc.com"

                        }

                    ]

                },

                "type": "PUSH"

            }

        }

    }

}

I tried using the translate activity to produce JSON but hitting the same issue as this blog:

https://svgonugu.com/2015/12/27/using-translate-activity-for-xml-to-json/

Using NSXD with File Adapter works but not with Translate activity.

Note: When the file adapter is used it writes a json file and there's no $ symbols in it. Which is what I was hoping to get through translate activity.

Now I can build the json string by concatinating parts of the string and that works fine when assiged to JSON object variable. I can successfully call the REST service. This soultion however doesnt feel slick or graceful.

Anyone any idea how to achieve this using translate activity or may be through javascript activity or if there's any other way that I am missing?

Thanks,

RK

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 21 2016
Added on Nov 23 2016
0 comments
1,594 views