Alemão
Alemão

Reputation: 33

WSO2 ESB -Xml to JSON with xsi:nil=true

How to convert xml elements to json with xsi:nil=true.

Example:

XML:

<Element1>10</Element1>
<ELement2 xsi:nil=true/>

JSON:

{
    Element1: 10,
    Element2: null
}

I am using PayloadFactory to generate json.

Upvotes: 0

Views: 1338

Answers (2)

Narges Ghelichi
Narges Ghelichi

Reputation: 1

If you set the

 synapse.commons.enableXmlNilReadWrite=true 

property in the synapse.properties file (stored in the <EI_HOME>/conf/ directory), XML elements where the 'nil' attribue is set to true will be represented in JSON as null objects as shown below.

{"object":null}

Upvotes: 0

Tharik Kanaka
Tharik Kanaka

Reputation: 2510

You can simply use data mapper mediator [1] for XML to JSON conversion. For custom mapping you can use the UI of WSO2 Developer Studio ESB tool [2]

[1] https://docs.wso2.com/display/ESB500/Data+Mapper+Mediator

[2] https://docs.wso2.com/display/ESB500/Using+Data+Mapper+Mediator+in+WSO2+ESB

Upvotes: 1

Related Questions