IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  How to convert XML Pipeline to JSON?

    Posted Tue August 13, 2019 03:08 PM

    Hi everyone.

    We would like to know about how to convert the XML generated by Software AG Designer.

    See the example below:

    <IDataXMLCoder version="1.0">
    <record javaclass="com.wm.util.Values">
    <value name="IFRESULT">Z</value>
    <value name="IFMESSAGE">Great</value>
    </record>
    </IDataXMLCoder>

    Is there a way to convert the above information to JSON?

    We are currently developing a Python program that will try to do this conversion. But, first, we would like to know if this already exists.

    Thanks in advance :smiley:


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 2.  RE: How to convert XML Pipeline to JSON?

    Posted Tue August 13, 2019 03:31 PM

    if you have a document structure in IS, just call pub.json:documentToJSONString to have the json string.


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 3.  RE: How to convert XML Pipeline to JSON?

    Posted Wed August 14, 2019 12:25 AM

    Hi Renan

    Yes. webMethods Java API comes with “com.wm.util.coder.XMLCoderWrapper” class which can be used to achieve what you are seeking. It is a 2 step process:

    • Write a java service (sample below) to convert your XML decoder file into proper IData
    • Convert IData into JSON using the “pub.json:documentToJSONString” service like Tong advised or if comfortable with Java it can be converted to JSON in same java service above using “com.wm.util.coder.IDataJSONCoder” class.

    If my understanding is correct, you are expecting response something like in the image file attached.

    
    IDataMap pipeMap = new IDataMap(pipeline);
    String pipeXML = pipeMap.getAsString("pipeXML");
    com.wm.util.coder.XMLCoderWrapper xmlCoder = new com.wm.util.coder.XMLCoderWrapper();
    try{
    IData pipeData = xmlCoder.decode(new ByteArrayInputStream(pipeXML.getBytes(StandardCharsets.UTF_8)));
    pipeMap.put("pipeData", pipeData);
    }catch(Exception e){
    throw new ServiceException(e);
    }


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 4.  RE: How to convert XML Pipeline to JSON?

    Posted Wed August 14, 2019 01:00 AM

    Thanks Prasad, very interesting code to convert the xml to IData!

    @Renan, Add the below import statements for the above code to work.

    import java.io.ByteArrayInputStream;
    import java.nio.charset.StandardCharsets;
    import com.softwareag.util.IDataMap;


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 5.  RE: How to convert XML Pipeline to JSON?

    Posted Wed August 14, 2019 09:55 AM

    All of you are great!!

    Thank you so much! This was exactly what we are searching for. It would be tough if we tried to do this using Python.

    Have a great day!


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services