In this post, we will discuss about using Translate activity for converting XML to JSON. This is one of the functionalities I wanted to try since release of 12c as nxsd has been enhanced to handle JSON as well. So I tried this using BPEL in both 12.1.3 and 12.2.1 but found to be not working as expected. Hence I will just mention about approach to use Translate activity. And will show you how its working with File Adapter.
Create a BPEL process and drag Translate activity.
Click gear icon to define NXSD schema as per required JSON data.
Finish the wizard as shown below to create NXSD.
Create BPEL variable varJson of NXSD complex type as shown below.
Create XSLT transformation to transform the input variable to varJson. For simplicity, we considered the NXSD structure almost similar to inputVariable.
Now modify Translate activity by giving required values for all other fields.
Click OK. Now our BPEL process should look like below.
Deploy the composite and test to observe the following error.
Note: Please note that the issue has been fixed in latest releases of SOA suite as observed by readers.
However, the same XML to JSON translation is working as expected with File Adapter. Create file adapter using below screenshots using Write operation.
Now in BPEL process, create invoke activity to invoke the file adapter.
Now create XSLT to transform inputVariable to inputFileWrite.
Now deploy composite again and test using same input as above. Now we will observe an output file in directory D as shown below.
You can find a sample project here having both of the cases discussed above.