java – XML to JSON conversion: why my 1st xml tag is getting skipped?
while converting XML to JSON my 1st XML tag into JSON is getting skipped
Here is the JAVA code snippet:
String="";
data = FileUtils.readFileToString(new File("src/main/resources/student.xml"), "UTF-8");
XmlMapper xmlMapper = new XmlMapper();
JsonNode jsonNode = xmlMapper.readTree(data.getBytes());
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.writerWithDefaultPrettyPrinter().writeValue(newFile("src/main/resources/student.json"),jsonNode);
here is the input:
<?xml version="1.0" encoding="utf-8"?>
<AccumulateResponse>
<TestCase>
<Transactionid>str1234</Transactionid>
<TransactionType>str1234</TransactionType>
<Status>str1234</Status>
</TestCase>
<TestCase>
<Transactionid>str5678</Transactionid>
<TransactionType>str5678</TransactionType>
<Status>str5678</Status>
</TestCase>
</AccumulateResponse>
here is the output:
{
"TestCase": [
{
"Transactionid": "str1234",
"TransactionType": "str1234",
"Status": "str1234"
},
{
"Transactionid": "str5678",
"TransactionType": "str5678",
"Status": "str5678"
}
]
}
here is the required Output:
{
"AccumulateResponse": {
"TestCase": [
{
"Transactionid": "str1234",
"TransactionType": "str1234",
"Status": "str1234"
},
{
"Transactionid": "str5678",
"TransactionType": "str5678",
"Status": "str5678"
}
]
}
}
AccumulateResponse tag is getting skipped.
Read more here: Source link