jackson-dataformat-xml icon indicating copy to clipboard operation
jackson-dataformat-xml copied to clipboard

Support extracting the whole DOM model under given XML element

Open rauluka opened this issue 5 years ago • 0 comments

Let's have a following XML:

<rootElement>
  <firstElement>value</firstElement>
  <rawElement>
    <elemen1>text</element1>
    <element2> ... </lement2>
  </rawElement>
<rootElement>

Support use-case of extracting contents of the whole <rawElement> DOM structure. <rawElement> can be any proper XML, text or CDATA block of unknown structure. The idea is to make it possible to extract such structure and save it rawElement field of your POJO.

Currently (2.11) to achieve it, inside a JsonDeserializer for rawElement you can read tree using json parser, however it's not possible to get XML structure. You can use the JsonNode & put it into XMLMapper.writeValueAsString, still it's a workaround rather than a solution.

According to Tatu from jackson-user: "it'd be necessary to expose a "native" XML type, like org.w3c.dom.Node (or Element?). Currently binding would try to re-parse textual content, but it would be relatively easy to change that, possibly along with configuration setting to select new or old approach."

rauluka avatar Jul 16 '20 17:07 rauluka