I have a xml message that needs to be converted to json message format. The xml message has xml schema defined that has type information for the elements. However, the resulting json has all the values as text values instead of boolean/number as mentioned in the xml schema. How do I instruct the XmlMapper() to derive the type information from the xml schema?
XmlMapper xmlMapper = new XmlMapper();
String xmlMsg = getResourceContent("test.xml");
JsonNode node = xmlMapper.readTree(xmlMsg.getBytes());
ObjectMapper jsonMapper = new ObjectMapper();
String json = jsonMapper.writeValueAsString(node);
Sample xml:
<myMessage>
<id>333</id>
<type>Text</type>
<flag>true</flag>
</myMessage>
Resulting json:
{
"id": "333",
"type": "Text",
"flag": "true"
}
Expected json:
{
"id": 333,
"type": "Text",
"flag": true
}