1

I would like to convert xml structure into json by using Jackson library

input xml:

<?xml version="1.0" encoding="UTF-8"?>
<xmldata>
  <groups>
    <fields>
      <disabled>true</disabled>
    </fields>
  </groups>
</xmldata>

output json should be:

{
  "xmldata": {
    "groups": {
      "fields": { 
        "disabled": true
      }
    }
  }
}

but instead of "disabled": true (boolean) I get "disabled": "true" (string)

do I need to add some configuration or is it not possible out-of-the-box?

I'm using this mapper config:

JacksonXmlModule module = new JacksonXmlModule();
module.setDefaultUseWrapper(false);
XmlFactory xmlFactory = new XmlFactory(new WstxInputFactory(), new WstxOutputFactory());
XmlMapper xmlMapper = new XmlMapper(xmlFactory, module);
xmlMapper.registerModule(new Jdk8Module());
xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);

PS: no POJOs involved (and I would like to keep it that way)

Thx in advance

regards

rome
  • 476
  • 1
  • 9
  • 19
  • I don't know the way how to do it without POJO class, because the `true` or `false` can be the text String. So, if you want boolean object, you need the POJO class, and specify boolean object there. – BSeitkazin Oct 31 '18 at 10:21

0 Answers0