I am trying to figure out the best approach for custom parsing of JSON object into an XML document.
Given the following JSON (I use JSON.org):
{"CfgAccessGroup":{"CfgGroup":{"capacityRuleDBID":{"value":0},"DBID":{"value":97},"siteDBID":{"value":0},"name":{"value":"EVERYONE"},"quotaTableDBID":{"value":0},"contractDBID":{"value":0},"state":{"value":1},"capacityTableDBID":{"value":0},"tenantDBID":{"value":1}},"xmlns":"http://schemas.genesyslab.com/Protocols/Configuration/ConfServer/2005/","type":{"value":6},"memberIDs":{"CfgID":[{"CSID":{"value":0},"DBID":{"value":5195},"type":{"value":3}},{"CSID":{"value":0},"DBID":{"value":12854},"type":{"value":3}},{"CSID":{"value":0},"DBID":{"value":12863},"type":{"value":3}},{"CSID":{"value":0},"DBID":{"value":5808},"type":{"value":3}}]}}}
I have tried to basically reconvert the JSON to XML by doing:
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = db.parse(new InputSource(new StringReader(XML.toString(object))));
However, the output is:
<CfgAccessGroup>
<CfgGroup>
<capacityRuleDBID>
<value>
0
</value>
</capacityRuleDBID>
...
<CfgGroup>
</CfgAccessGroup>
I need it to be:
...
<capacityRuleDBID value=0 />
...
Honestly I don't really know where to start.