DataPower

DataPower

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

Conversion from JSON to BadgerFish XML

  • 1.  Conversion from JSON to BadgerFish XML

    Posted 11/18/19 09:29 AM
    I am facing technical challenge while converting JSON to BadgerFish XML where proper BadgerFish XML is not getting formed while iterating over the loop and throwing below error. I understand there is something which I am unable to fix in the for loop ( Highlighted in BOLD)

    Any help in fixing this highly appreciated. 

    errorDescription: 'Unable to convert JSON to XML. The input is not in the specified format.',
    errorSuggestion: 'Inspect the JSON and correct it to adhere to the specified format as necessary.',
    status: 500,

    Code Snippet:

    let { req } = context
    let reqBody = req.body

    let RepaymentAmount = {}
    for (let el in reqBody.LoanRepaymentDetails) {
                RepaymentAmount[el] = {$:reqBody.LoanRepaymentDetails[el]
    }
    }

    let bfReqBody = {
    LoanPmtCalcInqRq: {
    'LoanRepaymentDetails':{
    RepaymentAmount
    },
    },
    }

    let xmlReqBody = converter.toXML('badgerfish', bfReqBody)


    Input JSON:

    {{ "LoanRepaymentDetails": [{ "PaymentType": "com.anz.InterestPayment", "PmtTimeframe": { "RecurrenceRule": { "RecurrenceType": "MAR" } } }, { "PaymentType": "com.anz.PrincipalPayment", "PmtTimeframe": { "RecurrenceRule": { "RecurrenceType": "Monthly" } } }]}

    Desired XML:

    <LoanPmtCalcInqRq><LoanPmtCalcInqRq><LoanRepaymentDetails> <RepaymentAmount> <PaymentType>com.anz.InterestPayment</PaymentType> <PmtTimeframe> <RecurrenceRule> <RecurrenceType>MAR</RecurrenceType> </RecurrenceRule> </PmtTimeframe> </RepaymentAmount> <RepaymentAmount> <PaymentType>com.anz.PrincipalPayment</PaymentType> <PmtTimeframe> <RecurrenceRule> <RecurrenceType>Monthly</RecurrenceType> </RecurrenceRule> </PmtTimeframe> </RepaymentAmount> </LoanRepaymentDetails></LoanPmtCalcInqRq>

    Desired BadgerFish intermediate to be formed

    "LoanPmtCalcInqRq":{"LoanRepaymentDetails":{"RepaymentAmount":{"PaymentType":{"$":{"com.anz.InterestPayment"}}
    "PmtTimeframe":{"RecurrenceRule":{"RecurrenceType":{$:"MAR"}}}},
    "RepaymentAmount":{"PaymentType":{"$":{"com.anz.PrincipalPayment"}}
    "PmtTimeframe":{"RecurrenceRule":{"RecurrenceType":{$:"Monthly"}}}}}




    ------------------------------
    Varun Rao
    ------------------------------