I'm trying to to convert an xml string to Json in Java. Here is a sample code:
import org.apache.commons.json.utils.XML;
String test = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><a><b>val1</b><d/></a>";
InputStream is = new ByteArrayInputStream(test.getBytes());
String jsonString = XML.toJson(is);
The result is:
{"a":{"b":"val1","d":true}}
I don't understand why d's value is set to true ?
Also is there any way to get this result:
{"a":{"b":"val1","d":""}}
I did a little investigation, org.apache.apache.wink.json4j.utils.XML.toJson method uses SAXParser , i couldn't debugged(it warned me due to missing line number attributes(is it because of decompiler?), anyway) it, but i think it makes true for empty tag.
Then I debugged apache.sling.commons.xml.XML.toJSONObject it has own XMLTokenizer. In my estimation because of SAXParser empty tag comes true.