'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.
Solution 1:[1]
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
Solution 2:[2]
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}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tharik Kanaka |
| Solution 2 | Narges Ghelichi |
