Layer7 API Management

Expand all | Collapse all

API gateway 9.0 - problem in json to xml assertion

Jump to Best Answer
  • 1.  API gateway 9.0 - problem in json to xml assertion

    Posted 11-08-2016 10:18 AM

    Hi ,
       We are on version 9.0 of API gateway and when using json to xml transformation ( standard Transformation convention ) we see a rearrangement of sequence of elements in the converted output xml when compared to the input json :

    Is there a way to avoid the assertion from not rearranging the sequence when converting from json to xml ? The rearrangement is causing issues since the output xml is used to route to a SOAP service that is expecting the sequence of xml elements to be the same as it occurs on the input json payload

     

    This is causing a problem since we are using the output xml to be put into a SOAP body and routing to a SOAP service end point that is particular about the sequence of elements occurring in the payload submitted to it.

     

    Input Json :

    *******************************************************************
    {
    "First_Name": "Lei",
    "Impact": "4-Minor/Localized",
    "Last_Name": "Liu",
    "Reported_Source": "Web",
    "Service_Type": "User Service Request",
    "Status": "New",
    "Action": "CREATE",
    "Summary": "test",
    "Notes": "test",
    "Urgency": "4-Low",
    "Template_Name": "Create New SRM Profile",
    "Vendor_Ticket_Number": "TKT-123",
    "Login_ID":"test"
    }
    *************************************************************************
    Output XML :
    *****************************************************************
    <?xml version="1.0" encoding="UTF-8"?>
    <JSONtoXMLResult>
        <Impact>4-Minor/Localized</Impact>
        <Status>New</Status>
        <Action>CREATE</Action>
        <Template_Name>Create New SRM Profile</Template_Name>
        <First_Name>Lei</First_Name>
        <Vendor_Ticket_Number>TKT-123</Vendor_Ticket_Number>
        <Last_Name>Liu</Last_Name>
        <Service_Type>User Service Request</Service_Type>
        <Summary>test</Summary>
        <Login_ID>test</Login_ID>
        <Reported_Source>Web</Reported_Source>
        <Urgency>4-Low</Urgency>
        <Notes>test</Notes>
    </JSONtoXMLResult>
    ***********************************************************************



  • 2.  Re: API gateway 9.0 - problem in json to xml assertion

    Posted 11-08-2016 11:10 AM

    From the JSON spec at http://json.org :

     

    An object is an unordered set of name/value pairs. However, the XML schema might be imposing an order which the conversion from JSON might not respect; which seems to be the issue you're encountering.

     

    Upon initial review, this was raised to our Engineering team and a hotfix may have been provided, but it looks like for a different version. You have already opened up a new case to track and work through this.

     

    -Alec Daniello



  • 3.  Re: API gateway 9.0 - problem in json to xml assertion
    Best Answer

    Posted 11-08-2016 03:11 PM

    Just so everyone is aware, there is a workaround in place. You can apply a XSL Transformation to the policy to order things how you want as our Gateway doesn't preserve the element order. 

     

    Apply XSL Transformation Assertion - CA API Gateway - 9.1 - CA Technologies Documentation 

     

    -Alec Daniello



  • 4.  Re: API gateway 9.0 - problem in json to xml assertion

    Posted 11-08-2016 05:09 PM

    Great workaround Alec!



  • 5.  Re: API gateway 9.0 - problem in json to xml assertion

    Posted 11-09-2016 03:22 AM

    I ran into the same issue some time ago and have created an idea for it: JSON to XML transformation with ordered XML



  • 6.  Re: API gateway 9.0 - problem in json to xml assertion

    Posted 04-11-2017 09:56 PM

    Thanks MichielHelder,

    It is very useful. XSLT can be used as a workaround to get the xml sequencing correct.

    What about XML to JSON, have you faced similar sequencing issue in JSON output?

     

    One of my client is looking for solution, if there is any sequencing issue with XML to JSON  using "Apply JSON Transformation" assertion.