External tag <item> when transform JsonNode to XML using jackson-dataformat-xml

16 views
Skip to first unread message

Fares

unread,
Dec 21, 2024, 4:28:13 PM12/21/24
to jackson-user

Hello,

I would like to bring up an issue that was raised in a forum. Here is the link: https://github.com/FasterXML/jackson/discussions/259

I am reaching out to you to gather more information on the subject.

Thank you for your help.

After migration from spring boot 3.2.2 to 3.3.5 ,

I'm facing an issue with the jackson-dataformat-xml library when transforming JSON to XML . The generated XML output has changed unexpectedly, causing errors in my results.

Here's the JSON input:

{
"root": {
    "toto": "value",
    "blocA": {
        "subEle": "helloWorld"
    }
}

With jackson-dataformat-xml:2.15.3, the XML output is correct:

<root>
    <toto>value</toto>
    <blocA>
        <subEle>helloWorld</subEle>
    </blocA>
</root>

However, after upgrading jackson-dataformat-xml:2.17.2, an additional tag <item> wrapper element appears:

<root>
     
<item>
        <toto>value</toto>
        <blocA>
            <subEle>helloWorld</subEle>
        </blocA>
     </item>
</root>

this is my instrcutions

JsonNode jsonNode= new ObjectMapper().readTree(JSON_TXT);

  XmlMapper xmlMapper = new XmlMapper();
 
  String xmlRequest = xmlMapper.writer().withRootName("root").writeValueAsString(jsonNode.elements());


After searching it' seem The issue is reproducible starting from version 2.16.0-rc1 ( the last one which was OK is 2.15.4)

Reply all
Reply to author
Forward
0 new messages