0

I have some JSON provided by a system out of my control that includes XML in some of the JSON values (in unpredictable locations).

Example:

{
    "glossary": {
        "title": "example glossary",
        "extras": "<details>
                      <detail>This is a detail</detail>
                    </details>"
    }
}

I'm using Jackson to parse this into a JsonNode and then a Jackson XMLMapper to write it out as XML, however at this point all of the < characters become &lt; and my XML blocks are just strings.

I'd like to, after parsing with Jackson and writing back out to XML again using XMLMapper end up with an output like as follows:

<ObjectNode>
    <glossary>
        <title>example glossary</title>
        <extras>
            <details>
                <detail>This is a detail</detail>
            </details>
        </extras>
    </glossary>
</ObjectNode>

I'm not entirely adverse to walking the entire tree and looking for valid XML sub-elements, but I'm not sure I see a way to do this given that JsonNode is immutable. Also, I ought to be slightly defensive against genuine uses of the < symbol (i.e. JSON values that are not valid XML).

Any thoughts as to how I could do this?

tmgstevens
  • 114
  • 1
  • 7

0 Answers0